solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char tmp[2001];
string a[2001];
int ans[2001];
void init() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) scanf("%s", &tmp), a[i] = tmp;
for (int i = 1; i <= n; i++)
for (int j = 0; j < m; j++) {
if (j - i + 1 >= 0 && a[i][j - i + 1] == 'R') ans[j]++;
if (j + i - 1 < m && a[i][j + i - 1] == 'L') ans[j]++;
if (i + i - 1 <= n && a[i + i - 1][j] == 'U') ans[j]++;
}
for (int i = 0; i < m; i++) cout << ans[i] << " ";
}
int main() {
init();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 5;
int res[maxn];
char ch[maxn][maxn];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", ch[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (ch[i][j] == 'U') {
if (i % 2 == 0) res[j]++;
} else if (ch[i][j] == 'L') {
if (j - i >= 0) res[j - i]++;
} else if (ch[i][j] == 'R') {
if (j + i < m) res[j + i]++;
}
}
for (int i = 0; i < m; i++) {
printf("%d", res[i]);
if (i != m - 1)
printf(" ");
else
printf("\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, u;
int t[2005] = {0};
char c;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c;
if (c == 'R') {
u = i - 1 + j;
if (u <= m && u > 0) t[u]++;
} else if (c == 'L') {
u = j - i + 1;
if (u <= m && u > 0) t[u]++;
} else if (c == 'U') {
if (i % 2 != 0) t[j]++;
}
}
}
for (int i = 1; i <= m; i++) cout << t[i] << " ";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 2000 + 10;
int n, second, k, res[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> second >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < second; j++) {
char cell;
cin >> cell;
if (cell == 'U')
res[j] += !(i & 1);
else if (cell == 'R')
res[(j + i < second ? j + i : second)]++;
else if (cell == 'L')
res[(j - i >= 0 ? j - i : second)]++;
}
for (int i = 0; i < second; i++) cout << res[i] << ' ';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
char a[maxn][maxn];
int w[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char ch[4] = {'L', 'R', 'U', 'D'};
int main() {
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 1; i < n; i++)
for (int l = 0; l < 4; l++) {
int xx = i + w[l][0] * i, yy = j + w[l][1] * i;
if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
if (a[xx][yy] == ch[l]) cnt++;
}
cout << cnt << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
int main() {
int n, m, k;
string in[2005];
cin >> n >> m >> k;
for (int i = 0; i < (n); i++) cin >> in[i];
for (int j = 0; j < (m); j++) {
int ret = 0;
for (int i = 0; i < (n); i++) {
if (j + i < m && in[i][j + i] == 'L') ret++;
if (i + i < n && in[i + i][j] == 'U') ret++;
if (j - i >= 0 && in[i][j - i] == 'R') ret++;
if (i - i >= 0 && in[i - i][j] == 'D') ret++;
}
cout << ret << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, K, nr[2010][2010], sum[2010];
char mat[2010][2010];
int main() {
std::ios_base::sync_with_stdio(false);
int i, j, t;
cin >> n >> m >> K;
for (i = 1; i <= n; ++i) cin >> (mat[i] + 1);
for (i = 1; i <= n; ++i) {
t = i - 1;
for (j = 1; j <= m; ++j) {
if (j - t > 0 && mat[i][j - t] == 'R') nr[i][j]++;
if (j + t <= m && mat[i][j + t] == 'L') nr[i][j]++;
if (i - t > 0 && mat[i - t][j] == 'D') nr[i][j]++;
if (i + t <= n && mat[i + t][j] == 'U') nr[i][j]++;
}
}
for (i = 1; i <= n; ++i)
for (j = 1; j <= m; ++j) sum[j] += nr[i][j];
for (j = 1; j <= m; ++j) cout << sum[j] << ' ';
cout << "\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long res[2009];
char c;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
for (long long i = (1); i < (n + 1); i++)
for (long long j = (1); j < (m + 1); j++) {
cin >> c;
if (c == 'U' && (i - 1) % 2 == 0) res[j]++;
if (c == 'D' && i == 1) res[j]++;
if (c == 'R' && i + j - 1 <= m) res[i + j - 1]++;
if (c == 'L' && j - i + 1 >= 1) res[j - i + 1]++;
}
for (long long i = (1); i < (m + 1); i++) cout << res[i] << " ";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2100;
int n, m, k;
char a[MAX_N][MAX_N];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < m; i++) {
int r = 0;
for (int j = 1; j < n; j++) {
if (j + j < n && a[j + j][i] == 'U') r++;
if (i + j < m && a[j][i + j] == 'L') r++;
if (i - j >= 0 && a[j][i - j] == 'R') r++;
}
cout << r << (i == m - 1 ? '\n' : ' ');
}
}
| 8 | CPP |
#include <bits/stdc++.h>
int n, m, k, i, j, dap[2020];
char map[2020];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < n; i++) {
scanf("%s", map);
for (j = 0; j < m; j++) {
if (map[j] == 'U') {
if (i % 2 == 0) dap[j]++;
} else if (map[j] == 'L') {
if (j - i >= 0) dap[j - i]++;
} else if (map[j] == 'R') {
if (j + i < m) dap[j + i]++;
}
}
}
for (i = 0; i < m; i++) {
printf("%d ", dap[i]);
}
return 0;
}
| 8 | CPP |
def ans():
n, m, k = map(int, input().split())
a = list([] for i in range(n))
s = [0]*m
for i in range(n):
a[i] = input()
for i in range(1,n):
for j in range(m):
if i < m-j and a[i][j+i] == 'L':
s[j]+=1
if i <= j and a[i][j-i] == 'R':
s[j]+=1
if i+i < n and a[i+i][j] == 'U':
s[j]+=1
print(*s)
ans() | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int arr[2005] = {0};
int main() {
int i, j, k, l, m, n;
string s[2005];
cin >> n >> m >> k;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 1; i < n; i++) {
int fr[2005] = {0};
for (j = 0; j < m; j++) {
if (s[i][j] == 'R' && j + i < m) {
fr[j + i]++;
} else if (s[i][j] == 'L' && j - i >= 0) {
fr[j - i]++;
}
}
for (j = 0; j < m; j++) {
arr[j] += fr[j];
}
}
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] == 'U') {
if (i % 2 == 0) {
arr[j]++;
}
}
}
}
for (i = 0; i < m; i++) {
cout << arr[i] << " ";
}
return 0;
}
| 8 | CPP |
n, m, k = map( int, input().split() )
ans = [0] * m
for i in range( n ):
field = input()
for j in range( m ):
if ( field[j] == 'U' ) and ( i % 2 == 0 ): ans[j] += 1
elif ( field[j] == 'L' ) and ( j >= i ): ans[j - i] += 1
elif ( field[j] == 'R' ) and ( j + i < m ): ans[j + i] += 1
print ( ' '.join( map( str, ans ) ) ) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, k;
bool f[4][N][N];
int ans[N];
string str;
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> str;
for (int j = 0; j < m; j++) {
if (str[j] == 'L') f[0][i][j] = 1;
if (str[j] == 'U') f[1][i][j] = 1;
if (str[j] == 'R') f[2][i][j] = 1;
if (str[j] == 'D') f[3][i][j] = 1;
}
}
for (int j = 0; j < m; j++)
for (int i = 0; i < n; i++) {
if (j - i >= 0 && f[2][i][j - i]) ans[j]++;
if (i + i < n && f[1][i + i][j]) ans[j]++;
if (j + i < m && f[0][i][j + i]) ans[j]++;
}
for (int i = 0; i < m; i++) cout << ans[i] << " ";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
return x * x;
}
template <typename T>
inline T abs(T x) {
return x > T() ? x : -x;
}
template <typename It>
ostream &outSeq(ostream &out, It begin, It end) {
out << "[";
while (begin != end) {
out << *begin;
++begin;
if (begin != end) {
out << ", ";
}
}
return out << "]";
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> const &a) {
return outSeq(out, (a).begin(), (a).end());
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> const &p) {
return out << "(" << p.first << ", " << p.second << ")";
}
namespace aux {
template <typename Tuple, size_t Size = tuple_size<Tuple>::value>
struct print_tuple;
template <typename Tuple>
struct print_tuple<Tuple, 0> {
ostream &operator()(ostream &out, Tuple t) { return out; }
};
template <typename Tuple, size_t Size>
struct print_tuple : private print_tuple<Tuple, Size - 1> {
ostream &operator()(ostream &out, Tuple t) {
print_tuple<Tuple, Size - 1>::operator()(out, t);
if (Size > 1) {
out << ", ";
}
return out << get<Size - 1>(t);
}
};
} // namespace aux
template <typename... Args>
ostream &operator<<(ostream &out, tuple<Args...> const &t) {
out << "(";
aux::print_tuple<tuple<Args...> >()(out, t);
return out << ")";
}
void showTime() {}
const int N = 2000;
struct Input {
int n, m, k;
string s[N];
void init(const Input &input) { *this = input; }
};
struct Data : Input {
bool read() {
if (!(cin >> n >> m >> k)) {
return 0;
}
getline(cin, s[0]);
for (int i = 0; i < int(n); ++i) {
getline(cin, s[i]);
}
return 1;
}
int ans[N];
void write() {
for (int i = 0; i < int(m); ++i) {
if (i) {
cout << " ";
}
cout << ans[i];
}
puts("");
}
virtual void solve() {}
virtual void clear() { *this = Data(); }
};
struct Solution : Data {
void solve() {
memset(ans, 0, sizeof ans);
for (int i = 0; i < int(n); ++i) {
for (int j = 0; j < int(m); ++j) {
if (s[i][j] == 'L') {
if (j - i >= 0) {
ans[j - i]++;
}
}
if (s[i][j] == 'R') {
if (j + i < m) {
ans[j + i]++;
}
}
if (s[i][j] == 'U') {
if (!(i & 1)) {
ans[j]++;
}
}
}
}
}
void clear() { *this = Solution(); }
};
Solution sol;
int main() {
sol.read();
sol.solve();
sol.write();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char a[2010][2010];
int main() {
int N, M, K, ans;
while (scanf("%d%d%d", &N, &M, &K) != EOF) {
for (int i = 0; i < N; i++) scanf("%s", a[i]);
for (int j = 0; j < M; j++) {
ans = 0;
for (int i = 1; i < N; i++) {
if (j - i >= 0 && a[i][j - i] == 'R') ans++;
if (i + i < N && a[2 * i][j] == 'U') ans++;
if (j + i < M && a[i][j + i] == 'L') ans++;
}
if (j != 0) printf(" ");
printf("%d", ans);
}
cout << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(2005);
int n, m;
char a[MAXN][MAXN];
int chk(int i, int j, char x) {
if (i < 0 || i >= n || j < 0 || j >= m) return 0;
if (a[i][j] == x) return 1;
return 0;
}
int main() {
int k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", a[i]);
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += chk(i + i, j, 'U');
cnt += chk(i - i, j, 'D');
cnt += chk(i, j + i, 'L');
cnt += chk(i, j - i, 'R');
}
printf("%d ", cnt);
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> v(m, 0);
string s;
cin >> s;
for (int i = 1; i < n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == 'D' || s[j] == '.') continue;
if (s[j] == 'L') {
if (j - i >= 0) v[j - i]++;
} else if (s[j] == 'R') {
if (i + j < m) v[i + j]++;
} else if (s[j] == 'U') {
if (i % 2 == 0) v[j]++;
}
}
}
for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) cout << " ";
cout << *it;
}
cout << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n, k;
char c;
cin >> n >> m >> k;
int i, j;
int* num = new int[m];
for (i = 0; i < m; i++) num[i] = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> c;
switch (c) {
case 'L':
if (j >= i) num[j - i]++;
break;
case 'R':
if (i + j < m) num[i + j]++;
break;
case 'U':
if (i % 2 == 0) num[j]++;
break;
case 'D':
break;
}
}
}
for (i = 0; i < m - 1; i++) cout << num[i] << " ";
cout << num[m - 1];
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int n, m, s;
char g[2005][2005];
int cnt[2005];
int main() {
memset(cnt, 0, sizeof(cnt));
scanf("%d %d %d", &n, &m, &s);
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
for (int j = 0; j < m; j++) {
if (g[i][j] == 'R') {
if (j + i < m) cnt[j + i]++;
} else if (g[i][j] == 'L') {
if (j - i >= 0) cnt[j - i]++;
} else if (g[i][j] == 'U') {
if (~i & 1) cnt[j]++;
}
}
}
for (int i = 0; i < m; i++) printf("%d ", cnt[i]);
puts("");
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int c[maxn][maxn];
int cs[maxn];
char s[maxn];
vector<pair<int, int> > vc;
vector<int> dvc;
const int U = 0;
const int D = 1;
const int L = 2;
const int R = 3;
inline int getD(char c) {
if (c == 'U') return U;
if (c == 'D') return D;
if (c == 'L') return L;
if (c == 'R') return R;
return 0;
}
int main() {
ios::sync_with_stdio(false);
int n, m, k;
memset(cs, 0, sizeof(cs));
memset(c, 0, sizeof(c));
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i < n + 1; ++i) {
scanf("%s", s + 1);
for (int j = 1; j < m + 1; ++j) {
if (s[j] != '.') {
++c[i][j];
vc.push_back(make_pair(i, j));
dvc.push_back(getD(s[j]));
}
}
}
int sz = ((int)(vc).size());
int x, y, d;
int t;
for (int j = 0; j < sz; ++j) {
x = vc[j].first;
y = vc[j].second;
d = dvc[j];
if (d == U) {
if (x > 1 && (x & 1)) ++cs[y];
} else if (d == L) {
t = x - 1;
y -= t;
if (y > 0 && y <= m) ++cs[y];
} else if (d == R) {
t = x - 1;
y += t;
if (y > 0 && y <= m) ++cs[y];
}
}
for (int j = 1; j < m + 1; ++j) printf("%d ", cs[j]);
putchar('\n');
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int main() {
while (cin >> n >> m >> p) {
string line;
bool a = true;
int ans[m];
memset(ans, 0, sizeof(ans));
for (int i = 0; i < n; ++i) {
getline(cin, line);
if (i == 0) {
if (a) {
i--;
a = false;
}
continue;
}
for (int j = 0; j < m; ++j) {
if (line[j] == '.') continue;
if (line[j] == 'R') {
if (i + j >= m) continue;
ans[j + i]++;
}
if (line[j] == 'L') {
if (j - i < 0) continue;
ans[j - i]++;
}
if (line[j] == 'U') {
if (i % 2 == 0) ans[j]++;
}
}
}
for (int i = 0; i < m; ++i) {
printf("%d ", ans[i]);
}
cout << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int main() {
int n, m, k, total = 1;
if (scanf("%d%d%d", &n, &m, &k)) {
int col[5000];
memset(col, 0, sizeof(col));
while (total <= m * n) {
char state;
int x, y;
if (total % m == 0)
x = m, y = total / m;
else
x = total % m, y = total / m + 1;
scanf(" %c", &state);
if (state == 'L')
if (x - y >= 0) col[x - y + 1]++;
if (state == 'R')
col[y + x - 1]++;
else if (state == 'U')
if (y % 2 != 0) col[x]++;
total++;
}
for (int i = 1; i <= m; i++) {
printf("%d", col[i]);
if (i != m) printf(" ");
}
printf("\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[2000][2005];
int a[2000];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < (int)(n); i++) scanf("%s", s[i]);
for (int i = 0; i < (int)(m); i++) a[i] = 0;
for (int i = 1; i < n; ++i)
for (int j = 0; j < (int)(m); j++) {
if (s[i][j] == 'U') {
if ((i & 1) == 0) ++a[j];
} else if (s[i][j] == 'R') {
if (j + i < m) ++a[j + i];
} else if (s[i][j] == 'L') {
if (j - i >= 0) ++a[j - i];
}
}
for (int i = 0; i < (int)(m); i++) printf("%d ", a[i]);
printf("\n");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char park[2007][2007];
int res[2007];
int n, m, k;
bool check(int x) { return (x >= 0 && x < m); }
int main() {
cin.sync_with_stdio(0);
cout.sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> park[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char c = park[i][j];
if (c == 'R')
if (check(i + j)) res[i + j]++;
if (c == 'L')
if (check(j - i)) res[j - i]++;
if (c == 'U')
if (!(i & 1)) res[j]++;
}
for (int i = 0; i < m; i++) cout << res[i] << " ";
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[2010][2010];
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", s + i);
for (int i = 0; i < m; i++) {
int r = 0;
for (int j = 1; j < n; j++) {
if (2 * j < n && s[2 * j][i] == 'U') r++;
if (i >= j && s[j][i - j] == 'R') r++;
if (j + i < m && s[j][i + j] == 'L') r++;
}
printf("%d ", r);
}
return 0;
}
| 8 | CPP |
def solve():
answer = [0] * m
for i in range(1, n):
for j in range(m):
if j - i >= 0:
if park[i][j - i] == 'R':
answer[j] += 1
if j + i < m:
if park[i][j + i] == 'L':
answer[j] += 1
if 2 * i < n:
if park[2 * i][j] == 'U':
answer[j] += 1
return answer
n, m, k = tuple(map(int, input().split()))
park = [input() for i in range(n)]
print(' '.join(map(str, solve())))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
int in() {
int r = 0, c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') return -in();
for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
;
return r;
}
char str[3000];
int mat[2020][2020];
int col[3000];
int main() {
int n = in();
int m = in();
int k = in();
memset(col, 0, sizeof col);
int i, j;
for (i = 0; i < n; i++) {
scanf("%s", str);
for (j = 0; j < m; j++) {
if (str[j] == 'L')
if (j - i >= 0) col[j - i]++;
if (str[j] == 'R')
if (j + i < m) col[j + i]++;
if (str[j] == 'U')
if (i % 2 == 0) col[j]++;
}
}
for (i = 0; i < m; i++) cout << col[i] << ' ';
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char a[2005][2005];
int main() {
int n, m, k;
int i, j;
int b[2005];
memset(b, 0, sizeof b);
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < n; i++) scanf("%s", a[i]);
for (i = 1; i < n; i++)
for (j = 0; j < m; j++) {
if (a[i][j] == 'R' && i + j < m) b[i + j]++;
if (a[i][j] == 'L' && j - i >= 0) b[j - i]++;
if (a[i][j] == 'U') {
if (i % 2 == 0) b[j]++;
}
}
for (i = 0; i < m; i++) printf("%d ", b[i]);
printf("\n");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
int n, m, k;
char G[maxn][maxn];
inline bool check(int x, int y) {
if (x > 0 && x < n && y >= 0 && y < m) return 1;
return 0;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", G[i]);
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 1; i < n; i++) {
if (check(i, j - i) && G[i][j - i] == 'R') cnt++;
if (check(i, j + i) && G[i][j + i] == 'L') cnt++;
if (check(i + i, j) && G[i + i][j] == 'U') cnt++;
}
printf("%d ", cnt);
}
printf("\n");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
char grid[MAXN][MAXN];
int N, M, K;
int l[MAXN];
int r[MAXN];
int u[MAXN];
int main(void) {
scanf("%d%d%d", &N, &M, &K);
for (int i = 0; i < N; ++i) {
scanf("%s", grid[i]);
for (int j = 0; j < M; ++j) {
if (grid[i][j] == 'U' && (i & 1) == 0) ++u[j];
if (grid[i][j] == 'R' && i + j < MAXN - 1) ++r[i + j];
if (grid[i][j] == 'L' && j - i >= 0) ++l[j - i];
}
}
for (int i = 0; i < M; ++i) {
printf("%d ", u[i] + r[i] + l[i]);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 20000000000000005ll;
const long long MOD = 1000000007;
int H, W, A[2005], K;
int main() {
cin >> H >> W >> K;
for (int i = (0); i <= (H - 1); i++) {
string s;
cin >> s;
for (int j = (0); j <= (W - 1); j++)
if (s[j] == 'U' && i % 2 == 0)
A[j]++;
else if (s[j] == 'L' && j - i >= 0)
A[j - i]++;
else if (s[j] == 'R' && j + i < W)
A[j + i]++;
}
for (int i = (0); i <= (W - 1); i++) cout << A[i] << " ";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void relax(T &a, T b) {
a = min(a, b);
}
template <class T>
void mrelax(T &a, T b) {
a = max(a, b);
}
int n, m, k;
char p[2010][2010];
bool check(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < (int)n; i++) scanf("%s", p[i]);
for (int j = 0; j < (int)m; j++) {
int cnt = 0;
for (int i = 0; i < (int)n; i++) {
if (check(i, j - i) && p[i][j - i] == 'R') ++cnt;
if (check(0, j) && p[0][j] == 'D') ++cnt;
if (check(i, i + j) && p[i][j + i] == 'L') ++cnt;
if (check(i + i, j) && p[i + i][j] == 'U') ++cnt;
}
printf("%d ", cnt);
}
puts("");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int ans[5001];
int t, n, m;
char s[5001];
int main() {
int n, m, t;
scanf("%d%d%d", &n, &m, &t);
for (int i = 0; i < n; i++) {
scanf("%s", s);
for (int j = 0; j < m; j++)
if (s[j] != '.') {
if (s[j] == 'D')
continue;
else if (s[j] == 'U' && (i % 2 == 0))
ans[j]++;
else if (s[j] == 'L' && j - i >= 0)
ans[j - i]++;
else if (s[j] == 'R' && j + i < m)
ans[i + j]++;
}
}
for (int i = 0; i < m; i++) printf("%d ", ans[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int ans[2005];
char mat[2005][2005];
void read() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= n; i++) scanf("%s", mat[i] + 1);
return;
}
void solve() {
int i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
if (mat[i][j] == 'R') {
int t = j + (i - 1);
if (t <= m) ans[t]++;
} else if (mat[i][j] == 'L') {
int t = j - (i - 1);
if (t >= 1) ans[t]++;
} else if (mat[i][j] == 'U')
if (i & 1) ans[j]++;
for (i = 1; i <= m; i++) printf("%d ", ans[i]);
puts("");
return;
}
int main() {
read();
solve();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[2222];
int n, m, k;
vector<char> spiders[2222];
string ss[2222];
int main(void) {
cin >> n >> m >> k;
for (int i = (0); i < (n); i++) cin >> ss[i];
for (int i = (0); i < (n); i++) {
for (int j = (0); j < (m); j++) {
if (i > 0) {
if (ss[i][j] == 'U' && i % 2 == 0) a[j]++;
if (ss[i][j] == 'D')
;
if (ss[i][j] == 'R') {
if (j + i < m) a[j + i]++;
}
if (ss[i][j] == 'L') {
if (j - i >= 0) a[j - i]++;
}
}
}
}
for (int i = (0); i < (m); i++) cout << a[i] << " ";
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
struct T {
int h, m;
};
bool fn(T a, T b) { return (a.h < b.h); }
using namespace std;
int main() {
int n, m, k, i, j;
cin >> n >> m >> k;
int ans[m];
string map[n];
for (i = 0; i < m; i++) ans[i] = 0;
for (i = 0; i < n; i++) cin >> map[i];
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (map[i][j] == 'U' && i % 2 == 0)
ans[j]++;
else if (map[i][j] == 'R') {
if ((i + j) < m) ans[i + j]++;
} else if (map[i][j] == 'L') {
if (j >= i) ans[j - i]++;
}
}
}
for (i = 0; i < m; i++) cout << ans[i] << " ";
cout << "\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char MAP[2001][2001];
int gb(int n, int m, int x, int y) {
int ans = 0;
if (x - y >= 0 && MAP[y][x - y] == 'R') ans++;
if (x + y < m && MAP[y][x + y] == 'L') ans++;
if (y * 2 < n && MAP[y * 2][x] == 'U') ans++;
return ans;
}
int main() {
int n, m, k;
int i, j;
cin >> n >> m >> k;
for (i = 0; i < n; i++) cin >> MAP[i];
for (i = 0; i < m; i++) {
int ans = 0;
for (j = 1; j < n; j++) {
ans += gb(n, m, i, j);
}
cout << ans;
if (i < m - 1)
cout << ' ';
else
cout << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
char ma[N][N];
int main() {
std::ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> ma[i][j];
}
}
for (int j = 0; j < m; ++j) {
int res = 0;
for (int i = 1; i < n; ++i) {
if (j - i >= 0) res += (int)(ma[i][j - i] == 'R');
if (j + i < m) res += (int)(ma[i][j + i] == 'L');
if (i + i < n) res += (int)(ma[2 * i][j] == 'U');
}
cout << res << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
int N, M, K;
cin >> N >> M >> K;
vector<string> mat(N);
for (int i = 0; i < N; ++i) {
cin >> mat[i];
}
for (int i = 0; i < M; ++i) {
int ans = 0;
for (int j = 0; j < N; ++j) {
const int dy[] = {0, 1, 0, -1};
const int dx[] = {1, 0, -1, 0};
const string dir = "LURD";
for (int di = 0; di < 4; ++di) {
int ni = i + dx[di] * j;
int nj = j + dy[di] * j;
if (not(0 <= ni and ni < M and 0 <= nj and nj < N)) continue;
ans += mat[nj][ni] == dir[di];
}
}
cout << ans << " \n"[i + 1 == M];
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char s[2222][2222];
int a[2222];
int main() {
int i, j, n, m, k;
cin >> n >> m >> k;
for (i = 0; i < n; i++) cin >> s[i];
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] == 'U') {
if (i % 2 == 0) a[j]++;
} else if (s[i][j] == 'R') {
if (i + j < m) a[i + j]++;
} else if (s[i][j] == 'L') {
if (j - i >= 0) a[j - i]++;
}
}
}
for (i = 0; i < m; i++) cout << a[i] << ' ';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int ans[2010];
int main() {
int n, m, k;
string s;
char x;
cin >> n >> m >> k;
for (int i = 0; i < m; i++) ans[i] = 0;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
x = s[j];
if (x == 'U') {
if (i % 2 == 0) ans[j]++;
} else if (x == 'R') {
if (j + i < m) ans[j + i]++;
} else if (x == 'L') {
if (j - i >= 0) ans[j - i]++;
}
}
}
for (int i = 0; i < m; i++) cout << ans[i] << " ";
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167177216")
using namespace std;
const int INF = 1e9;
const long double eps = 1e-9;
const long long MOD = (long long)(4e6 + 37);
const long long INF64 = (long long)(INF) * (long long)(INF);
const int ddx[] = {-1, 1, 1, -1};
const int ddy[] = {1, 1, -1, -1};
const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dxh[] = {-1, -1, -1, 1, 1, 1, 1, -1};
const int dyh[] = {1, -1, -1, -1, -1, 1, 1, 1};
const string dirs[] = {"RIGHT", "UP", "LEFT", "DOWN"};
string s[2222];
char a[2222][2222];
int n, m, k;
int up[2222];
int main() {
cin >> n >> m >> k;
getline(cin, s[0]);
for (int i = 1; i <= n; i++) {
getline(cin, s[i]);
for (int j = 0; j < m; j++) {
a[i][j + 1] = s[i][j];
if (s[i][j] == 'U' && i != 2 && i % 2 == 1) up[j + 1]++;
}
}
for (int j = 1; j <= m; j++) {
int ans = 0;
ans += up[j];
int len = 0;
for (int i = 2; i <= n; i++) {
len++;
int l = j - len, r = j + len;
if (l >= 1 && a[i][l] == 'R') ans++;
if (r <= m && a[i][r] == 'L') ans++;
}
cout << ans << ' ';
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, i, j, kt = 0;
cin >> n >> m >> k;
string s[2003];
for (i = 0; i < n; i++) cin >> s[i];
int pos[2003];
memset(pos, 0, sizeof(pos));
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] != '.') {
if (s[i][j] == 'L') {
if (j - i >= 0) pos[j - i]++;
} else if (s[i][j] == 'R') {
if (j + i < m) pos[j + i]++;
} else if (s[i][j] == 'U' && i % 2 == 0) {
pos[j]++;
}
}
}
}
for (i = 0; i < m; i++) {
cout << pos[i] << ' ';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long n, m, k;
cin >> n >> m >> k;
vector<vector<char> > matrix(n, vector<char>(m, ' '));
for (long long row = 0; row < n; row++) {
for (long long col = 0; col < m; col++) {
cin >> matrix[row][col];
}
cout << endl;
}
for (long long col = 0; col < m; col++) {
long long total = 0;
for (long row = 1; row < n; row++) {
if (row <= col && matrix[row][col - row] == 'R') total++;
if ((row + col) < m && matrix[row][col + row] == 'L') total++;
if (row % 2 == 0 && matrix[row][col] == 'U') total++;
}
cout << total << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int mod = (int)1e9 + 7;
const long double INF = (long double)(1e3);
const int N = 2005;
int n, m, k;
int a[N];
void upd(int i, int j, int cur) {
if (cur == 0) {
if (j - i >= 0) a[j - i]++;
}
if (cur == 1) {
if (j + i <= m - 1) a[i + j]++;
}
if (cur == 2) {
if (i % 2 == 0) {
a[j]++;
}
}
}
int main() {
cin >> n >> m >> k;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < m; ++j) {
if (s[j] == 'L')
upd(i, j, 0);
else if (s[j] == 'R')
upd(i, j, 1);
else if (s[j] == 'U')
upd(i, j, 2);
}
}
for (int(i) = 0; (i) < (m); ++(i)) printf("%d ", a[i]);
return 0;
}
| 8 | CPP |
n, m, k = map(int, str.split(input()))
f = tuple(map(lambda _: str.strip(input()), range(n)))
r = []
for x in range(m):
cr = sum(map(lambda y: f[y][x] == "U", range(0, n, 2)))
for cx in range(max(0, x + 1 - n), x):
cr += f[x - cx][cx] == "R"
for cx in range(x + 1, min(m, n + x)):
cr += f[cx - x][cx] == "L"
r.append(cr)
print(str.join(" ", map(str, r)))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m, k, ans[2111];
char a[2111];
int main() {
scanf("%d%d%d\n", &n, &m, &k);
for (int i = 0; i < n; ++i) {
scanf("%s\n", a);
for (int j = 0; j < m; ++j) {
if (a[j] == 'R' && j + i < m) ans[j + i]++;
if (a[j] == 'L' && j - i >= 0) ans[j - i]++;
if (a[j] == 'U' && i % 2 == 0) ans[j]++;
}
}
for (int i = 0; i < m; ++i) printf("%d ", ans[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
char s[2010][2010];
int ans[2010];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) scanf("%s", s[i]);
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (s[0][j] == 'D') ans[j]++;
if (j >= i && s[i][j - i] == 'R') ans[j]++;
if (j + i < m && s[i][j + i] == 'L') ans[j]++;
if (i + i < n && s[i + i][j] == 'U') ans[j]++;
}
}
for (int i = 0; i < m; i++) {
cout << ans[i];
if (i == m - 1)
cout << endl;
else
cout << " ";
}
}
| 8 | CPP |
''' ===============================
-- @uthor : Kaleab Asfaw
-- Handle : kaleabasfaw2010
-- Bio : High-School Student
==============================='''
# Fast IO
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file): self._fd = file.fileno(); self.buffer = BytesIO(); self.writable = "x" in file.mode or "r" not in file.mode; self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b: break
ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0; return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)); self.newlines = b.count(b"\n") + (not b); ptr = self.buffer.tell(); self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1; return self.buffer.readline()
def flush(self):
if self.writable: os.write(self._fd, self.buffer.getvalue()); self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file): self.buffer = FastIO(file); self.flush = self.buffer.flush; self.writable = self.buffer.writable; self.write = lambda s: self.buffer.write(s.encode("ascii")); self.read = lambda: self.buffer.read().decode("ascii"); self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout); input = lambda: sys.stdin.readline().rstrip("\r\n")
# Others
# from math import floor, ceil, gcd
# from decimal import Decimal as d
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
ans = 1
for i in range(1, x+1): ans = (ans * i) % mod
return ans
def arr2D(n, m, default=0): return [[default for j in range(m)] for i in range(n)]
def arr3D(n, m, r, default=0): return [[[default for k in range(r)] for j in range(m)] for i in range(n)]
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}
class DSU:
def __init__(self, length): self.length = length; self.parent = [-1] * self.length # O(log(n))
def getParent(self, node, start): # O(log(n))
if node >= self.length: return False
if self.parent[node] < 0:
if start != node: self.parent[start] = node
return node
return self.getParent(self.parent[node], start)
def union(self, node1, node2): # O(log(n))
parent1 = self.getParent(node1, node1); parent2 = self.getParent(node2, node2)
if parent1 == parent2: return False
elif self.parent[parent1] <= self.parent[parent2]: self.parent[parent1] += self.parent[parent2]; self.parent[parent2] = parent1
else: self.parent[parent2] += self.parent[parent1]; self.parent[parent1] = parent2
return True
def getCount(self, node): return -self.parent[self.getParent(node, node)] # O(log(n))
def exact(num):
if abs(num - round(num)) <= 10**(-9):return round(num)
return num
def solve(n, m, k, lst):
ans = []
for j in range(m):
cnt = 0
for i in range(n):
if j - i >= 0:
if lst[i][j-i] == "R": cnt += 1
if j + i < m:
if lst[i][j+i] == "L": cnt += 1
if i - i >= 0:
if lst[i-i][j] == "D": cnt += 1
if i + i < n:
if lst[i+i][j] == "U": cnt += 1
ans.append(cnt)
for i in ans: print(i, end=" ")
print()
n, m, k = list(map(int, input().split()))
lst = []
for i in range(n):
lst.append(input())
solve(n, m, k, lst) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char s[2001][2001];
long long cont[100004];
int main() {
int n, m, p, i, j, k;
cont[0] = 0;
scanf("%d%d%d", &n, &m, &p);
for (i = 0; i < n; i++) scanf("%s", s[i]);
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] == 'U') {
if (i % 2 == 0 && j + 1 > 0) cont[1 + j]++;
} else if (s[i][j] == 'R' && i + j + 1 > 0) {
cont[i + j + 1]++;
} else if (s[i][j] == 'L' && j - i + 1 > 0) {
cont[j - i + 1]++;
}
}
}
for (i = 1; i <= m; i++) printf("%I64d ", cont[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int n, m, k;
int s[2001] = {};
int main() {
int i, j, k;
int min;
char c[2010];
;
scanf("%d%d%d", &n, &m, &k);
for (i = 1; i <= n; i++) {
scanf("%s", c);
for (j = 0; j <= m - 1; j++) {
switch (c[j]) {
case 'U':
if (i % 2 == 1) s[j + 1]++;
break;
case 'L':
if (j - i + 2 >= 1) s[j - i + 2]++;
break;
case 'R':
if (j + i <= m) s[j + i]++;
break;
default:
break;
}
}
}
printf("%d", s[1]);
for (i = 2; i <= m; i++) {
printf(" %d", s[i]);
}
printf("\n");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = ((1 << 30) - 1);
const long long linf = ((1ll << 62) - 1);
const int N = 2001;
int n, m, k;
int l[N][N], r[N][N], u[N][N], d[N][N];
int cnt[N][N], sum[N];
int main() {
assert(scanf("%d%d%d", &n, &m, &k) == 3);
for (int i = 0; i < n; i++) {
static char buf[100500];
assert(scanf("%s", buf) == 1);
for (int j = 0; j < m; j++) {
if (buf[j] == 'L')
l[i][j]++;
else if (buf[j] == 'R')
r[i][j]++;
else if (buf[j] == 'U')
u[i][j]++;
else if (buf[j] == 'D')
d[i][j]++;
}
}
for (int t = 0; t < n; t++)
for (int y = 0; y < m; y++) {
if (y - t >= 0) cnt[t][y] += r[t][y - t];
if (y + t < m) cnt[t][y] += l[t][y + t];
if (2 * t < n) cnt[t][y] += u[2 * t][y];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) sum[j] += cnt[i][j];
for (int i = 0; i < m; i++) printf("%d%c", sum[i], " \n"[i + 1 == m]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans[2111];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
char c[2111];
scanf("%s", &c);
for (int j = 0; j < m; j++) {
if (c[j] == 'U' && (i % 2 == 0)) ans[j]++;
if (c[j] == 'L' && j - i >= 0) ans[j - i]++;
if (c[j] == 'R' && j + i < m) ans[j + i]++;
}
}
for (int i = 0; i < m; i++) printf("%d ", ans[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int n, m, k;
char mp[2222][2222];
int ans[2222];
bool valid(int i, int j, char ch) {
if (i < 0 || i >= n || j < 0 || j >= m || mp[i][j] != ch) {
return false;
}
return true;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
scanf("%s", mp[i]);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[j] += valid(i, j - i, 'R');
ans[j] += valid(i, j + i, 'L');
ans[j] += valid(i + i, j, 'U');
}
}
for (int i = 0; i < m; i++) {
printf("%d ", ans[i]);
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e+5 + 10;
const int INF = 2e+9;
const double e = 1e-8;
int t[2000];
int m[2000];
int h[2000];
bool u[2000];
int main() {
int n, m, k;
cin >> n >> m >> k;
char c;
int cnt[2000];
for (int i = 0; i < m; i++) {
cnt[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> c;
if (c == 'U') {
if (i % 2 == 0) {
cnt[j]++;
}
}
if (c == 'R') {
if ((i + j) < m) {
cnt[i + j]++;
}
}
if (c == 'L') {
if ((j - i) >= 0) {
cnt[j - i]++;
}
}
}
}
for (int i = 0; i < m; i++) {
cout << cnt[i] << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
return out << "(" << pair.first << ", " << pair.second << ")";
}
const int N = 2e3 + 5;
int res[N];
void Deb(int i, int j, int k) {}
int main() {
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(10);
double beg = 1.0 * clock() / CLOCKS_PER_SEC;
int n, m, sp;
cin >> n >> m >> sp;
;
for (int i = (1); i <= (n); ++i) {
for (int j = (1); j <= (m); ++j) {
char c;
cin >> c;
;
if (c == '.') {
continue;
}
if (c == 'U') {
if (i % 2 == 1) {
res[j]++;
Deb(i, j, j);
}
} else if (c == 'D') {
if (i == 1) {
res[j] += n;
}
} else {
int col;
if (c == 'R') {
col = j + i - 1;
} else {
col = j - i + 1;
}
if (col >= 1 && col <= m) {
res[col]++;
Deb(i, j, col);
}
}
}
}
for (int i = (1); i <= (m); ++i) {
cout << res[i] << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[2005][2005];
int ans[2005];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) scanf("%s", s[i]);
for (int i = 1; i < n; ++i)
for (int j = 0; j < m; ++j) {
if (s[i][j] == 'R' && i + j < m) ans[i + j]++;
if (s[i][j] == 'L' && j - i >= 0) ans[j - i]++;
if (s[i][j] == 'U' && i % 2 == 0) ans[j]++;
}
for (int i = 0; i < m; ++i) printf("%d ", ans[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2005;
int n, m, k;
char B[Maxn][Maxn];
int Check(int r, int c, char need) {
return 0 <= r && r < n && 0 <= c && c < m && B[r][c] == need;
}
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", B[i]);
for (int j = 0; j < m; j++) {
int res = 0;
for (int i = 1; i < n; i++)
res += Check(i, j - i, 'R') + Check(i, j + i, 'L') + Check(i + i, j, 'U');
printf("%d%c", res, j + 1 < m ? ' ' : '\n');
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2011;
int a[MAXN][MAXN];
char str[MAXN];
int N, M, K;
int solve(int c) {
int ret = 0;
for (int i = 2; i <= N; i++) {
int nj;
nj = c + (i - 1);
if (nj <= M && a[i][nj] == 1) ret++;
nj = c - (i - 1);
if (nj >= 1 && a[i][nj] == 2) ret++;
if (a[i][c] == 3 && i % 2 == 1) ret++;
}
return ret;
}
int main() {
while (scanf("%d%d%d", &N, &M, &K) > 0) {
for (int i = 1; i <= N; i++) {
scanf("%s", str);
for (int j = 1; j <= M; j++) {
switch (str[j - 1]) {
case '.':
case 'D':
a[i][j] = 0;
break;
case 'L':
a[i][j] = 1;
break;
case 'R':
a[i][j] = 2;
break;
case 'U':
a[i][j] = 3;
break;
}
}
}
for (int j = 1; j <= M; j++) {
if (j != 1) printf(" ");
int nans = solve(j);
printf("%d", nans);
}
printf("\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<string> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
int ans = 0;
for (int j = 0; j < n; ++j) {
if (a[j][i] == 'U' && j % 2 == 0) {
++ans;
}
}
for (int j = 0; j < n && i + j < m; ++j) {
if (a[j][i + j] == 'L') {
++ans;
}
}
for (int j = 0; j < n && i - j >= 0; ++j) {
if (a[j][i - j] == 'R') {
++ans;
}
}
cout << ans << ' ';
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2000 + 20;
int res[MAX_N];
char _map[MAX_N][MAX_N];
int n, m, k;
bool isOK(int i, int j) {
if (i < 0 || j < 0 || i >= n || j >= m) return false;
return true;
}
int main() {
memset(res, 0, sizeof(res));
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", _map[i]);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (isOK(j, i - j) && _map[j][i - j] == 'R') res[i]++;
if (isOK(j, i + j) && _map[j][i + j] == 'L') res[i]++;
if (isOK(j << 1, i) && _map[j << 1][i] == 'U') res[i]++;
}
}
printf("%d", res[0]);
for (int i = 1; i < m; i++) printf(" %d", res[i]);
puts("");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mang[111111];
int m, n, k;
char a[2222][2222];
int main() {
scanf("%d%d%d\n", &m, &n, &k);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) scanf("%c", &a[i][j]);
scanf("\n");
}
memset(mang, 0, sizeof(mang));
int x;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
if (a[i][j] != '.') {
if (a[i][j] == 'D')
continue;
else if (a[i][j] == 'U') {
if (i % 2) mang[j]++;
} else if (a[i][j] == 'R') {
x = j + (i - 1);
if (x <= n) mang[x]++;
} else if (a[i][j] == 'L') {
x = j - (i - 1);
if (x >= 1) mang[x]++;
}
}
for (int i = 1; i <= n; i++) printf("%d ", mang[i]);
return 0;
}
| 8 | CPP |
class CodeforcesTask436BSolution:
def __init__(self):
self.result = ''
self.n_m_k = []
self.field = []
def read_input(self):
self.n_m_k = [int(x) for x in input().split(" ")]
for x in range(self.n_m_k[0]):
self.field.append(input())
def process_task(self):
result_row = [0 for x in range(self.n_m_k[1])]
for x in range(self.n_m_k[0]):
for y in range(self.n_m_k[1]):
# print(x, y)
field = self.field[x][y]
if field == "R":
pos = y + x
if pos < self.n_m_k[1]:
result_row[pos] += 1
elif field == "L":
pos = y - x
if pos >= 0:
result_row[pos] += 1
elif field == "U" and not x % 2:
result_row[y] += 1
self.result = " ".join([str(x) for x in result_row])
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask436BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int cnt[2005];
char ss[2005], now;
int main() {
int i, j, tmp;
scanf("%d %d %d", &N, &M, &tmp);
for (i = 1; i <= N; i++) {
scanf("%s", ss);
for (j = 1; j <= M; j++) {
now = ss[j - 1];
if (now == 'U')
cnt[j] += (i & 1);
else if (now == 'D')
cnt[j] += N * (i == 1);
else if (now == 'R') {
tmp = j + i - 1;
if (tmp <= M) cnt[tmp]++;
} else if (now == 'L') {
tmp = j - i + 1;
if (tmp >= 1) cnt[tmp]++;
}
}
}
for (i = 1; i <= M; i++) printf("%d ", cnt[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 2002;
string s[N];
int ans[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j >= i && s[i][j - i] == 'R') ans[j]++;
if (j + i < m && s[i][j + i] == 'L') ans[j]++;
if (i + i < n && s[i + i][j] == 'U') ans[j]++;
}
}
for (int i = 0; i < m; i++) cout << ans[i] << " ";
}
| 8 | CPP |
def f():
n, m, k = map(int, input().split())
s = []
a = []
for i in range(n):
s.append(input())
for j in range(m):
ans = 0
for i in range(n):
if i + i < n and s[i + i][j] == 'U':
ans += 1
if j - i >= 0 and s[i][j - i] == 'R':
ans += 1
if j + i < m and s[i][j + i] == 'L':
ans += 1
a.append(ans)
print(' '.join(map(str, a)))
f()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2007;
char a[maxn][maxn];
int n, m, k;
int calc(int col) {
int res = 0;
for (int i = 3; i <= n; i += 2)
if (a[i][col] == 'U') ++res;
int i = 2, j = col - 1;
while (i <= n && j >= 1) {
if (a[i][j] == 'R') ++res;
++i;
--j;
}
i = 2;
j = col + 1;
while (i <= n && j <= m) {
if (a[i][j] == 'L') ++res;
++i;
++j;
}
return res;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1, _c = n; i <= _c; i++) scanf("%s", a[i] + 1);
for (int i = 1, _c = m; i <= _c; i++) printf("%d ", calc(i));
return 0;
}
| 8 | CPP |
n,m,k=[int(x) for x in input().split()]
park=[input() for i in range(n)]
answers=[0]*m
for inot in range(n):
for j in range(m):
if park[inot][j]!='.':
i=(j,inot,park[inot][j])
if i[2]=='R':
if i[0]+i[1]<m:
answers[i[0]+i[1]]+=1
elif i[2]=='L':
if i[0]-i[1]>=0:
answers[i[0]-i[1]]+=1
elif i[2]=='U':
if not i[1]&1:
answers[i[0]]+=1
for i in answers:
print(i,end=' ') | 8 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n, m, k;
char s[2002];
long long r[2000] = {};
std::scanf("%d%d%d\n", &n, &m, &k);
for (int i(0); i < n; ++i) {
std::fgets(s, sizeof(s), stdin);
for (int j(0); j < m; ++j) {
switch (s[j]) {
case 'D':
r[j] += i == 0;
break;
case 'U':
r[j] += i % 2 == 0;
break;
case 'R':
k = i + j;
if (k < m) r[k]++;
break;
case 'L':
k = j - i;
if (0 <= k) r[k]++;
break;
}
}
}
std::ios::sync_with_stdio(false);
for (int i(0); i < m; ++i) {
if (0 < i) std::cout << ' ';
std::cout << r[i];
}
std::cout << std::endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
char a[maxn][maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k, x, ans = 0;
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
for (int j = 0; j < m; j++) {
ans = 0;
for (int i = 0; i < n; i++) {
if (2 * i < maxn) {
if (a[i + i][j] == 'U') ans++;
}
if (i + j < maxn) {
if (a[i][j + i] == 'L') ans++;
}
if (j >= i) {
if (a[i][j - i] == 'R') ans++;
}
}
cout << ans << " ";
}
}
| 8 | CPP |
I = lambda:map(int,input().split())
n,m,k = I()
f = [['.' for _ in range(m)] for _ in range(n)]
for i in range(n):
s = input()
for j in range(len(s)):
if s[j] != '.':
f[i][j] = s[j]
ans = [0] * m
for i in range(n):
for j in range(m):
if j - i >= 0 and f[i][j - i] == 'R':
ans[j] += 1
if j + i < m and f[i][j + i] == 'L':
ans[j] += 1
if f[0][j] == 'D':
ans[j] += 1
if i + i < n and f[i + i][j] == 'U':
ans[j] += 1
print (*ans) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <class C>
void operator<<(vector<C> &v, const C &x) {
v.push_back(x);
}
template <class D>
void operator>>(vector<D> &v, D &x) {
assert(!v.empty());
x = v.back();
v.pop_back();
}
template <class E>
void operator<<(set<E> &v, const E &x) {
v.insert(x);
}
template <class F>
void operator<<(queue<F> &c, const F &v) {
v.push(v);
}
template <class G>
void operator>>(queue<G> &c, const G &v) {
const G r = v.front();
v.pop();
return r;
}
const int inf = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
const int maxn = 2020;
string s[maxn];
int ans[maxn];
int main() {
ios_base::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> s[i];
for (int j = 0; j < m; ++j) {
int t;
switch (s[i][j]) {
case 'U':
if (i % 2 == 0) ans[j]++;
break;
case 'R':
t = i + j;
if (t < maxn) ans[t]++;
break;
case 'L':
t = j - i;
if (t >= 0) ans[t]++;
break;
}
}
}
for (int j = 0; j < m; ++j) {
cout << ans[j] << ' ';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char ar[2005][2005];
int main() {
int n;
int m;
int k;
cin >> n >> m >> k;
string s;
for (long long i = 0; (i) < (n); ++i) {
cin >> ar[i];
}
int x = 0;
while (x < m) {
long long ans = 0;
long long y = 0;
while (y != n - 1) {
y++;
if (x - y >= 0 && ar[y][x - y] == 'R') ans++;
if (x + y < m && ar[y][x + y] == 'L') ans++;
if (y + y < n && ar[y + y][x] == 'U') ans++;
}
cout << ans << " ";
x++;
}
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
char tmp[2222];
int ans[2222];
int main() {
int n, m, i, j, k;
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < n; i++) {
scanf("%s", tmp);
for (j = 0; j < m; j++) {
switch (tmp[j]) {
case 'R':
if (0 <= j + i && j + i < m) ans[j + i]++;
break;
case 'L':
if (0 <= j - i && j - i < m) ans[j - i]++;
break;
case 'D':
break;
case 'U':
if (i % 2 == 0) ans[j]++;
break;
}
}
}
for (i = 0; i < m; i++) {
printf("%d ", ans[i]);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 2000 + 4, Inf = 1e9 + 10;
int n, m, k;
char f[M][M];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> f[i][j];
for (int i = 0; i < m; i++) {
int ans = 0;
for (int y = 2; y < n; y += 2)
if (f[y][i] == 'U') ans++;
for (int x = i, y = 0; x >= 0 && y < n; y++, x--)
if (f[y][x] == 'R') ans++;
for (int x = i, y = 0; x < m && y < n; y++, x++)
if (f[y][x] == 'L') ans++;
cout << ans << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, res[2020] = {0};
string s[2020];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 1; i < n; i++)
for (int j = 0; j < m; j++) {
if (j - i >= 0 && s[i][j - i] == 'R') res[j]++;
if (j + i < m && s[i][j + i] == 'L') res[j]++;
if (i + i < n && s[i + i][j] == 'U') res[j]++;
}
for (int i = 0; i < m; i++) cout << res[i] << " ";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
X gcd(X a, X b) {
if (!b)
return a;
else
return gcd(b, a % b);
}
int main() {
int n, m, k;
cin >> n >> m >> k;
string str[n + 1];
for (int i = 0; i < n; i++) cin >> str[i];
vector<int> v;
for (int i = 0, j = 0; j < m; i++, j++) {
int cnt = 0;
for (int l = 1, t = 1; l < n; l++, t++) {
if (j - t >= 0) {
if (str[l][j - t] == 'R') cnt++;
}
if (j + t < m) {
if (str[l][j + t] == 'L') cnt++;
}
if (l + t < n) {
if (str[l + t][j] == 'U') cnt++;
}
if (l - t >= 0) {
if (str[l - t][j] == 'D') cnt++;
}
}
v.push_back(cnt);
}
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i < v.size() - 1) cout << " ";
}
cout << "\n";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector<int> res(m, 0);
string cur;
for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
i += 1 - 2 * ((0) > (n))) {
cin >> cur;
for (__typeof(cur.size()) j = (0) - ((0) > (cur.size()));
j != (cur.size()) - ((0) > (cur.size()));
j += 1 - 2 * ((0) > (cur.size()))) {
if (cur[j] == 'U' && (i & 1) == 0)
res[j]++;
else if (cur[j] == 'R' && (int)j + i < m)
res[j + i]++;
else if (cur[j] == 'L' && (int)j - (int)i >= 0)
res[j - i]++;
}
}
for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
i += 1 - 2 * ((0) > (m)))
cout << res[i] << " \n"[i == m - 1];
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long int n, m, k;
int valid(int i, int j) {
if (i >= 0 && i < n && j >= 0 && j < m)
return 1;
else
return 0;
}
int main() {
cin >> n >> m >> k;
char v[2005][2005];
string temp = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cin >> v[i][j];
}
vector<int> a(m, 0);
long long int c = 0, t;
for (int j = 0; j < m; j++) {
c = 0;
for (int i = 1; i < n; i++) {
t = i;
if (valid(i - t, j) && v[i - t][j] == 'D') {
c++;
}
if (valid(i + t, j) && v[i + t][j] == 'U') {
c++;
}
if (valid(i, j - t)) {
if (v[i][j - t] == 'R') c++;
}
if (valid(i, j + t) && v[i][j + t] == 'L') {
c++;
}
}
a[j] = c;
}
for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, v[2005];
char a[2005][2005];
void Citire() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> (a[i] + 1);
}
void Rez() {
int t, solutie = 0;
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
t = i - 1;
if (i - t >= 1 && a[i - t][j] == 'D') solutie++;
if (i + t <= n && a[i + t][j] == 'U') solutie++;
if (j - t >= 1 && a[i][j - t] == 'R') solutie++;
if (j + t <= m && a[i][j + t] == 'L') solutie++;
}
v[j] = solutie;
solutie = 0;
}
for (int i = 1; i <= m; i++) cout << v[i] << " ";
cout << "\n";
}
int main() {
Citire();
Rez();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char grid[2002][2002];
int u[2002], r[2002], l[2002], d[2002];
bool OK(char a) {
return (a == 'U' || a == 'D' || a == 'L' || a == 'R' || a == '.');
}
int GetAnsFor(int col) {
int ret = 0;
int i, j;
for (i = 1; i <= n; i++) {
if (i % 2 == 0) continue;
if (grid[i][col] == 'U') {
ret++;
}
}
for (i = 1; i <= n; i++) {
if (col - i + 1 >= 1) {
if (grid[i][col - i + 1] == 'R') {
ret++;
}
}
if (col + i - 1 <= m) {
if (grid[i][col + i - 1] == 'L') {
ret++;
}
}
}
return ret;
}
int main() {
int i, j, ii, jj, ind;
scanf("%d %d %d", &n, &m, &k);
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
scanf("%c", &grid[i][j]);
if (!OK(grid[i][j])) {
j--;
continue;
}
}
}
for (i = 1; i <= m; i++) {
printf("%d", GetAnsFor(i));
if (i == m)
printf("\n");
else
printf(" ");
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char str[2005][2005], ch[] = {'L', 'R', 'U', 'D'};
int spider[2005] = {0};
queue<pair<int, int> > q[4];
int main() {
int n, m, k;
cin >> n >> m >> k;
getchar();
for (int i = 0; i < n; i++) gets(str[i]);
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < 4; k++)
if (str[i][j] == ch[k]) q[k].push(pair<int, int>(i, j));
}
}
for (int i = 0; i < 4; i++) {
while (!q[i].empty()) {
pair<int, int> f = q[i].front();
int x = f.first, y = f.second;
q[i].pop();
if (i == 0) {
if (y - x >= 0) {
spider[y - x]++;
}
}
if (i == 1) {
if (y + x < m) {
spider[y + x]++;
}
}
if (i == 2) {
if (x % 2 == 0) spider[y]++;
}
}
}
for (int i = 0; i < m; i++) cout << spider[i] << " ";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[2001];
char s[20001];
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
gets(s);
for (int i = 0; i < n; i++) {
gets(s);
for (int j = 0; j < m; j++)
if (s[j] == 'U' && i % 2 == 0)
a[j]++;
else if (s[j] == 'L') {
int cc = j - i;
if (cc >= 0) a[cc]++;
} else if (s[j] == 'R') {
int cc = j + i;
if (cc < m) a[cc]++;
}
}
for (int i = 0; i < m; i++) printf("%d ", a[i]);
putchar('\n');
getchar();
getchar();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char start[2048][2048];
string str;
int R, C, K;
inline bool check(int x, int y) {
if (x < 0 || x >= C) return false;
if (y < 0 || y >= R) return false;
return true;
}
int solve(int col, int row, int turn) {
if (row >= R) return 0;
int res = 0;
int x, y;
x = col;
y = row - turn;
if (check(x, y) && start[y][x] == 'D') res++;
x = col;
y = row + turn;
if (check(x, y) && start[y][x] == 'U') res++;
x = col - turn;
y = row;
if (check(x, y) && start[y][x] == 'R') res++;
x = col + turn;
y = row;
if (check(x, y) && start[y][x] == 'L') res++;
return res + solve(col, row + 1, turn + 1);
}
int main() {
cin >> R >> C >> K;
for (int i = 0; i < R; i++) {
cin >> str;
for (int j = 0; j < C; j++) start[i][j] = str[j];
}
for (int i = 0; i < C - 1; i++) cout << solve(i, 0, 0) << " ";
cout << solve(C - 1, 0, 0) << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<pair<char, pair<int, int> > > spiders;
string s;
int n, m, k;
int a[2002][2002];
int ans[2002];
void nextT(int T) {}
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < m; j++)
if (s[j] != '.') {
if (s[j] == 'R') {
if (i + j < m) ans[i + j]++;
} else if (s[j] == 'L') {
if (j - i >= 0) ans[j - i]++;
} else if (s[j] == 'U' && i % 2 != 1)
ans[j]++;
}
}
for (int i = 0; i < m; i++) cout << ans[i] << " ";
cout << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int tot[2200];
int main() {
int n, m, kk;
scanf("%d%d%d\n", &n, &m, &kk);
int i, j, k, x, y, z;
char ch;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
ch = getchar();
if (ch == 'R') {
x = i + j;
if (x >= 0 && x < m) tot[x]++;
}
if (ch == 'L') {
x = j - i;
if (x >= 0 && x < m) tot[x]++;
}
if (ch == 'D') {
}
if (ch == 'U') {
tot[j] += (i + 1) % 2;
}
}
ch = getchar();
}
for (i = 0; i < m; i++) {
printf("%d ", tot[i]);
}
printf("\n");
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct spider {
int y, x;
enum spider_type { Left, Right, Up, Down };
spider_type type;
spider() : y(-1), x(-1), type(Left) {}
spider(int y, int x, spider_type t) {
this->y = y;
this->x = x;
this->type = t;
}
};
int n, m, k;
class P436B_Solver {
public:
P436B_Solver() {}
void Input(std::istream &is = std::cin) {
is >> n >> m >> k;
spiders.resize(k);
int sc = 0;
for (int y = 0; y < n; ++y) {
string str;
is >> str;
for (size_t x = 0; x < str.size(); ++x) {
if (str[x] == 'L') {
spiders[sc++] = spider(y, x, spider::Left);
} else if (str[x] == 'R') {
spiders[sc++] = spider(y, x, spider::Right);
} else if (str[x] == 'D') {
spiders[sc++] = spider(y, x, spider::Down);
} else if (str[x] == 'U') {
spiders[sc++] = spider(y, x, spider::Up);
}
}
}
results.resize(m);
for (int i = 0; i < m; ++i) results[i] = 0;
}
void Solve() {
for (int si = 0; si < k; ++si) {
spider &s = spiders[si];
if (s.type == spider::Down) {
continue;
} else if (s.type == spider::Up) {
if (s.y % 2 == 0) results[s.x]++;
} else if (s.type == spider::Left) {
int index = s.x - s.y;
if (index >= 0 && index < m) results[index]++;
} else if (s.type == spider::Right) {
int index = s.y + s.x;
if (index >= 0 && index < m) results[index]++;
}
}
}
void Output(std::ostream &os = cout) {
for (int j = 0; j < m; ++j) {
os << results[j];
if (j != m - 1) os << " ";
}
}
private:
int n, m, k;
std::vector<spider> spiders;
std::vector<int> results;
};
void Test(const std::string &input, const std::string &output) {
std::stringstream in;
std::stringstream out;
in << input;
P436B_Solver solver;
solver.Input(in);
solver.Solve();
solver.Output(out);
if (out.str() == output)
cout << "Ok\n";
else
cout << "Fail!\n";
}
int main() {
P436B_Solver solver;
solver.Input();
solver.Solve();
solver.Output();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int max(int a, int b) { return a < b ? b : a; }
inline int min(int a, int b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
inline long long min(long long a, long long b) { return a > b ? b : a; }
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long inf = 1e18;
long long fl(long long x, long long y) {
if (x >= 0) return x / y;
return x / y - (x % y ? 1 : 0);
}
long long cl(long long x, long long y) {
if (x >= 0) return (x + y - 1) / y;
return x / y;
}
long long power(long long a, long long n) {
if (n == 0) {
return 1;
}
long long b = power(a, n / 2);
b = b * b % mod;
if (n % 2) b = b * a % mod;
return b;
}
char mat[2010][2010];
int A[2010][2010];
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; ++i) scanf("%s", mat[i]);
for (int i = 1; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i + i < n && mat[i + i][j] == 'U') A[i][j]++;
if (j - i >= 0 && mat[i][j - i] == 'R') A[i][j]++;
if (j + i < m && mat[i][j + i] == 'L') A[i][j]++;
}
}
for (int j = 0; j < m; ++j) {
int ans = 0;
for (int i = 0; i < n; ++i) ans += A[i][j];
printf("%d ", ans);
}
printf("\n");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const int MOD = 1000000007;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
for (int j = 0; j < m; ++j) {
int k = 0;
if (s[0][j] != '.') k++;
for (int i = 1; i < n; ++i) {
if (s[i - i][j] == 'D') k++;
if (j - i >= 0 && s[i][j - i] == 'R') k++;
if (j + i < m && s[i][j + i] == 'L') k++;
if (i + i < n && s[i + i][j] == 'U') k++;
}
cout << k << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char Mx[2010][2010];
int A[2000];
int main() {
int m, n;
long long k;
int i, j;
cin >> n >> m >> k;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cin >> Mx[i][j];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if ((Mx[i][j] == 'U') && (i % 2 == 1)) A[j]++;
if ((Mx[i][j] == 'L') && (j - i + 1 > 0)) A[j - i + 1]++;
if ((Mx[i][j] == 'R') && (j + i - 1 <= m)) A[j + i - 1]++;
}
}
for (j = 1; j <= m; j++) {
cout << A[j] << ' ';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const int N = 2007;
char st[N][N];
int n, m, k;
inline bool sym(char c) { return c == 'L' || c == 'R' || c == 'U' || c == 'D'; }
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) scanf("%s", st[i]);
for (int j = 0; j < m; ++j) {
int cur = 0;
for (int i = 0; i < n; ++i) {
if (st[i][j] == 'U' && i % 2 == 0) ++cur;
}
for (int k = 1; k < n; ++k)
if (j >= k && st[k][j - k] == 'R') ++cur;
for (int k = 1; k < n; ++k)
if (j + k < m && st[k][j + k] == 'L') ++cur;
printf("%d ", cur);
}
puts("");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
char s[2100][2100];
int ans[2100];
int main() {
int n, m, k;
scanf("%d%d%d\n", &n, &m, &k);
for (int i = 0; i < (int)(n); i++) gets(s[i]);
for (int i = 0; i < (int)(n); i++)
for (int j = 0; j < (int)(m); j++) {
if (s[i][j] == '.' || s[i][j] == 'D') continue;
if (s[i][j] == 'U') {
if (i % 2 == 1) continue;
ans[j]++;
continue;
}
int nj;
if (s[i][j] == 'L')
nj = j - i;
else
nj = j + i;
if (0 <= nj && nj < m) ans[nj]++;
}
for (int i = 0; i < (int)(m); i++) printf(i ? " %d" : "%d", ans[i]);
puts("");
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
register char c_;
register T _, __;
for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar())
if (c_ == '-') __ = -1;
for (; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
const int maxn = 2048;
int n, m, cnt[maxn];
char str[maxn];
int main() {
n = read<int>(), m = read<int>(), read<int>();
for (register int i = (1), i_end_ = (n); i <= i_end_; ++i) {
scanf("%s", str + 1);
for (register int j = (1), j_end_ = (m); j <= j_end_; ++j)
if (str[j] == 'U' && (i & 1))
++cnt[j];
else if (str[j] == 'L' && j >= i)
++cnt[j - i + 1];
else if (str[j] == 'R' && j + i - 1 <= m)
++cnt[j + i - 1];
}
for (register int i = (1), i_end_ = (m); i <= i_end_; ++i)
printf("%d ", cnt[i]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
const int infi = 1e9;
const long long Linfi = (long long)1e18;
const long long MOD = 1000000007;
int c1 = 9973;
struct nhen {
int x, y, direc;
nhen() {}
nhen(int _x, int _y, int _direc) {
x = _x;
y = _y;
direc = _direc;
}
};
int n, m, k, cnt = 0;
string s[2005];
nhen P[4000005];
int ans[2005];
void solve() {
for (int i = 1; i <= cnt; i++) {
if (P[i].direc == 1) {
if (P[i].y + P[i].x - 1 <= m) ans[P[i].x + P[i].y - 1]++;
} else if (P[i].direc == 3) {
if (P[i].y - P[i].x + 1 >= 1) ans[P[i].y - P[i].x + 1]++;
} else if (P[i].direc == 2) {
if (P[i].x % 2 == 1) ans[P[i].y]++;
} else if (P[i].direc == 4) {
if (P[i].x == 1) ans[P[i].y]++;
}
}
for (int i = 1; i <= m; i++) cout << ans[i] << " ";
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = '0' + s[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i][j] == 'R')
P[++cnt] = nhen(i, j, 1);
else if (s[i][j] == 'L')
P[++cnt] = nhen(i, j, 3);
else if (s[i][j] == 'U')
P[++cnt] = nhen(i, j, 2);
else if (s[i][j] == 'D')
P[++cnt] = nhen(i, j, 4);
}
}
solve();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e3 + 5;
char s[M][M];
int ans[M];
int32_t main() {
ios_base::sync_with_stdio(false);
;
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> s[i][j];
switch (s[i][j]) {
case 'U':
if (i & 1) ans[j]++;
break;
case 'R':
if (i + j - 1 <= m) ans[i + j - 1]++;
break;
case 'L':
if (j - i + 1 >= 1) ans[j - i + 1]++;
break;
}
}
for (int j = 1; j <= m; j++) cout << ans[j] << ' ';
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gint() {
int n;
scanf("%d", &n);
return n;
}
const int maxn = 1e5 + 10;
int n, m, k;
char s[2005][2005];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) scanf("%s", s[i]);
int ans = 0;
for (int i = 0; i < m; i++) {
ans = 0;
for (int j = 1; j < n && i + j < m; j++) {
if (s[j][i + j] == 'L') ans++;
}
for (int j = 1; j < n && (i - j) >= 0; j++)
if (s[j][i - j] == 'R') ans++;
for (int j = 1; j < n; j++)
if (s[j][i] == 'U' && j % 2 == 0) ans++;
printf("%d ", ans);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
struct Vec2 {
int x;
int y;
};
Vec2 operator*(const Vec2& left, int scalar) {
Vec2 result;
result.x = left.x * scalar;
result.y = left.y * scalar;
return result;
}
struct Vec2Hash {
int M_;
Vec2Hash(int M) : M_(M) {}
size_t operator()(const Vec2& vec) const { return M_ * vec.y + vec.x; }
};
Vec2 operator*(int scalar, const Vec2& right) { return right * scalar; }
bool operator==(const Vec2& left, const Vec2& right) {
return right.x == left.x && right.y == left.y;
}
Vec2 operator+(const Vec2& left, const Vec2& right) {
Vec2 result;
result.x = left.x + right.x;
result.y = left.y + right.y;
return result;
}
int spiders_met(const std::unordered_map<Vec2, Vec2, Vec2Hash>& spiders, int N,
int j) {
int spidersMet = 0;
static Vec2 dirs[] = {Vec2{-1, 0}, Vec2{1, 0}, Vec2{0, -1}, Vec2{0, 1}};
for (int i = 1; i < N; ++i) {
Vec2 testPos = {j, i};
for (int k = 0; k < 4; ++k) {
Vec2 pos = testPos + dirs[k] * i;
auto iter = spiders.find(pos);
if (iter != spiders.end() && (iter->second * (-1) == dirs[k])) {
++spidersMet;
}
}
}
return spidersMet;
}
int main() {
int N, M, spiderCount;
std::cin >> N;
std::cin >> M;
std::cin >> spiderCount;
std::unordered_map<Vec2, Vec2, Vec2Hash> spiders(spiderCount, Vec2Hash(M));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
char dir;
std::cin >> dir;
Vec2 step;
bool hasSpider = true;
switch (dir) {
case 'R':
step = {1, 0};
break;
case 'L':
step = {-1, 0};
break;
case 'U':
step = {0, -1};
break;
case 'D':
step = {0, 1};
break;
default:
hasSpider = false;
break;
}
if (hasSpider) {
Vec2 origin = {j, i};
spiders[origin] = step;
}
}
}
for (int j = 0; j < M; ++j) {
std::cout << spiders_met(spiders, N, j) << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int MAXN = 2020;
int a[MAXN][MAXN], dp[MAXN][MAXN];
int main() {
int n, m, k, i, j, ans;
char ch;
scanf("%d%d%d", &n, &m, &k);
getchar();
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
ch = getchar();
if (ch == 'R')
a[i][j] = 1;
else if (ch == 'L')
a[i][j] = 2;
else if (ch == 'U')
a[i][j] = 3;
else if (ch == 'D')
a[i][j] = 4;
else
a[i][j] = 0;
}
getchar();
}
memset(dp, 0, sizeof(dp));
for (i = n; i >= 2; i--)
for (j = 1; j <= m; j++)
if ((a[i][j] == 3) && (i % 2 == 1)) dp[(i + 1) / 2][j]++;
for (j = 1; j <= m; j++)
for (i = 1; i <= n; i++)
if ((a[i][j] == 1) && (i + j - 1 > 0) && (i + j - 1 <= m))
dp[i][i + j - 1]++;
for (j = m; j >= 1; j--)
for (i = 1; i <= n; i++)
if ((a[i][j] == 2) && (j - i + 1 > 0) && (j - i + 1 <= m))
dp[i][j - i + 1]++;
for (j = 1; j <= m; j++) {
ans = 0;
for (i = 1; i <= n; i++) ans += dp[i][j];
if (j < m)
printf("%d ", ans);
else
printf("%d\n", ans);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
unsigned R[2222];
int main() {
unsigned x, y, i, j, k;
char c;
scanf("%u%u%u", &x, &y, &k);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++) {
while ((c = getchar()) <= ' ')
;
if (c == 'U') {
if (!(i & 1)) R[j]++;
} else if (c == 'L') {
k = j - i;
if (k < y) R[k]++;
} else if (c == 'R') {
k = j + i;
if (k < y) R[k]++;
}
}
printf("%u", *R);
for (j = 0; ++j < y;) printf(" %u", R[j]);
putchar('\n');
return 0;
}
| 8 | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.