problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9 values |
|---|---|---|---|---|---|---|---|
p03053 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> Masu(H, vector<char>(W));
vector<vector<int>> Map(H, vector<int>(W, -1));
deque<int> queY;
deque<int> queX;
getchar();
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
Masu[i][j] = getchar();
if (Masu[i][j] == '#') {
queY.push_back(i);
queX.push_back(j);
Map[i][j] = 0;
}
}
getchar();
}
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
int ans = 0;
while (!queY.empty()) {
int y = queY.front(), x = queX.front();
queY.pop_front();
queX.pop_front();
int cnt = Map[y][x] + 1;
for (int i = 0; i < 4; i++) {
int newy = y + dy[i], newx = x + dx[i];
if (newy < 0 || newy >= H || newx < 0 || newx >= W)
continue;
else if (Map[newy][newx] == -1) {
queY.push_back(newy);
queX.push_back(newx);
Map[newy][newx] = cnt;
ans = max(ans, cnt);
}
}
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> Masu(H, vector<char>(W));
vector<vector<int>> Map(H, vector<int>(W, -1));
deque<int> queY;
deque<int> queX;
getchar();
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Masu[i][j] = getchar();
if (Masu[i][j] == '#') {
queY.push_back(i);
queX.push_back(j);
Map[i][j] = 0;
}
}
getchar();
}
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
int ans = 0;
while (!queY.empty()) {
int y = queY.front(), x = queX.front();
queY.pop_front();
queX.pop_front();
int cnt = Map[y][x] + 1;
for (int i = 0; i < 4; i++) {
int newy = y + dy[i], newx = x + dx[i];
if (newy < 0 || newy >= H || newx < 0 || newx >= W)
continue;
else if (Map[newy][newx] == -1) {
queY.push_back(newy);
queX.push_back(newx);
Map[newy][newx] = cnt;
ans = max(ans, cnt);
}
}
}
cout << ans << "\n";
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 868,694 | 868,695 | u501643136 | cpp |
p03053 | #include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <numeric>
#include <utility>
#include <vector>
#define sign(a) ((a > 0) - (a < 0))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL << 60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()
using namespace std;
void solve(long long H, long long W, std::vector<std::string> A) {
vector<vector<LL>> tab(H, vector<LL>(W, INF));
int ans = 0;
deque<pair<int, pair<int, int>>> q;
rep(i, H) {
rep(j, W) {
if (A[i][j] == '#') {
q.emplace_back(make_pair(0, make_pair(i, j)));
}
}
}
vector<vector<int>> dxdy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
while (!q.empty()) {
auto p = q.front();
auto i = p.second.first, j = p.second.second;
auto l0 = p.first;
q.pop_front();
if (l0 >= tab[i][j])
continue;
tab[i][j] = l0;
ans = max(l0, ans);
for (auto d : dxdy) {
auto i2 = i + d[0], j2 = j + d[1];
if (i2 < 0 || j2 < 0 || i2 >= H || j2 >= W)
continue;
q.emplace_back(make_pair(l0 + 1, make_pair(i2, j2)));
}
}
cout << ans << endl;
}
int main() {
long long H;
scanf("%lld", &H);
long long W;
scanf("%lld", &W);
std::vector<std::string> A(H);
for (int i = 0; i < W; i++) {
std::cin >> A[i];
}
solve(H, W, std::move(A));
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <numeric>
#include <utility>
#include <vector>
#define sign(a) ((a > 0) - (a < 0))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL << 60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()
using namespace std;
void solve(long long H, long long W, std::vector<std::string> A) {
vector<vector<LL>> tab(H, vector<LL>(W, INF));
int ans = 0;
deque<pair<int, pair<int, int>>> q;
rep(i, H) {
rep(j, W) {
if (A[i][j] == '#') {
q.emplace_back(make_pair(0, make_pair(i, j)));
}
}
}
vector<vector<int>> dxdy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
while (!q.empty()) {
auto p = q.front();
auto i = p.second.first, j = p.second.second;
auto l0 = p.first;
q.pop_front();
if (l0 >= tab[i][j])
continue;
tab[i][j] = l0;
ans = max(l0, ans);
for (auto d : dxdy) {
auto i2 = i + d[0], j2 = j + d[1];
if (i2 < 0 || j2 < 0 || i2 >= H || j2 >= W)
continue;
q.emplace_back(make_pair(l0 + 1, make_pair(i2, j2)));
}
}
cout << ans << endl;
}
int main() {
long long H;
scanf("%lld", &H);
long long W;
scanf("%lld", &W);
std::vector<std::string> A(H);
for (int i = 0; i < H; i++) {
std::cin >> A[i];
}
solve(H, W, std::move(A));
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 868,710 | 868,711 | u414425367 | cpp |
p03053 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int h, w;
vector<string> field(1000);
vector<vector<int>> d(1000, vector<int>(1000));
int INF = 1e9;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
void bfs() {
queue<P> que;
rep(i, h) rep(j, w) d[i][j] = INF;
rep(i, h) rep(j, w) if (field[i][j] == '#') {
d[i][j] = 0;
que.push(P(i, j));
}
while (que.size()) {
P p = que.front();
que.pop();
int x = p.first, y = p.second;
rep(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == INF) {
que.push(P(nx, y));
d[nx][ny] = d[x][y] + 1;
}
}
}
return;
}
int main() {
cin >> h >> w;
rep(i, h) cin >> field[i];
bfs();
int ans = 0;
rep(i, h) rep(j, w) ans = max(ans, d[i][j]);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int h, w;
vector<string> field(1000);
vector<vector<int>> d(1000, vector<int>(1000));
int INF = 1e9;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
void bfs() {
queue<P> que;
rep(i, h) rep(j, w) d[i][j] = INF;
rep(i, h) rep(j, w) if (field[i][j] == '#') {
d[i][j] = 0;
que.push(P(i, j));
}
while (que.size()) {
P p = que.front();
que.pop();
int x = p.first, y = p.second;
rep(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == INF) {
que.push(P(nx, ny));
d[nx][ny] = d[x][y] + 1;
}
}
}
return;
}
int main() {
cin >> h >> w;
rep(i, h) cin >> field[i];
bfs();
int ans = 0;
rep(i, h) rep(j, w) ans = max(ans, d[i][j]);
cout << ans << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 868,712 | 868,713 | u346629192 | cpp |
p03053 | #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
int h, w;
std::cin >> h >> w;
vector<string> grid(h);
rep(i, h) std::cin >> grid[i];
vector<vi> cost(h, vi(h, inf));
vi que;
rep(i, h) rep(j, w) {
if (grid[i][j] == '.')
continue;
cost[i][j] = 0;
que.pb(i * w + j);
}
int ans = 0;
rep(i, que.size()) {
int x = que[i] % w, y = que[i] / w;
srep(dx, -1, 2) srep(dy, -1, 2) if (dx * dx + dy * dy == 1) {
int nx = x + dx, ny = y + dy;
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (grid[ny][nx] == '#' || cost[ny][nx] != inf)
continue;
cost[ny][nx] = cost[y][x] + 1;
chmax(ans, cost[ny][nx]);
que.pb(ny * w + nx);
}
}
std::cout << ans << "\n";
}
| #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
int h, w;
std::cin >> h >> w;
vector<string> grid(h);
rep(i, h) std::cin >> grid[i];
vector<vi> cost(h, vi(w, inf));
vi que;
rep(i, h) rep(j, w) {
if (grid[i][j] == '.')
continue;
cost[i][j] = 0;
que.pb(i * w + j);
}
int ans = 0;
rep(i, que.size()) {
int x = que[i] % w, y = que[i] / w;
srep(dx, -1, 2) srep(dy, -1, 2) if (dx * dx + dy * dy == 1) {
int nx = x + dx, ny = y + dy;
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (grid[ny][nx] == '#' || cost[ny][nx] != inf)
continue;
cost[ny][nx] = cost[y][x] + 1;
chmax(ans, cost[ny][nx]);
que.pb(ny * w + nx);
}
}
std::cout << ans << "\n";
}
| [] | 868,735 | 868,736 | u700484101 | cpp |
p03053 | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
ll GCD(ll a, ll b) {
ll r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
ll LCM(ll a, ll b) {
ll c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
ll Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
return p;
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
return p;
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};
ll h, w;
cin >> h >> w;
vector<string> v(h);
rep(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, -1));
queue<pair<ll, ll>> que;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (v[i][j] == '#') {
a[i][j] = 0;
que.push(pair<ll, ll>(i, j));
}
}
}
while (!que.empty()) {
auto tmp = que.front();
que.pop();
for (ll i = 0; i < 4; i++) {
ll nx = tmp.first + dx[i];
ll ny = tmp.second + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (a[ny][nx] == -1) {
que.push(pair<ll, ll>(ny, nx));
a[ny][nx] = a[tmp.first][tmp.second] + 1;
}
}
}
ll ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, a[i][j]); }
}
cout << ans << endl;
} | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
ll GCD(ll a, ll b) {
ll r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
ll LCM(ll a, ll b) {
ll c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
ll Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
return p;
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
return p;
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};
ll h, w;
cin >> h >> w;
vector<string> v(h);
rep(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, -1));
queue<pair<ll, ll>> que;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (v[i][j] == '#') {
a[i][j] = 0;
que.push(pair<ll, ll>(i, j));
}
}
}
while (!que.empty()) {
auto tmp = que.front();
que.pop();
for (ll i = 0; i < 4; i++) {
ll nx = tmp.second + dx[i];
ll ny = tmp.first + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (a[ny][nx] == -1) {
que.push(pair<ll, ll>(ny, nx));
a[ny][nx] = a[tmp.first][tmp.second] + 1;
}
}
}
ll ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, a[i][j]); }
}
cout << ans << endl;
} | [
"expression.operation.binary.change"
] | 868,739 | 868,740 | u264265458 | cpp |
p03053 | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
ll GCD(ll a, ll b) {
ll r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
ll LCM(ll a, ll b) {
ll c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
ll Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
return p;
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
return p;
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};
ll h, w;
cin >> h >> w;
vector<string> v(h);
rep(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, -1));
queue<pair<ll, ll>> que;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (v[i][j] == '#') {
a[i][j] = 0;
que.push(pair<ll, ll>(i, j));
}
}
}
while (!que.empty()) {
auto tmp = que.front();
que.pop();
for (ll i = 0; i < 4; i++) {
ll nx = tmp.first + dx[i];
ll ny = tmp.second + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (a[ny][nx] == -1) {
que.push(pair<ll, ll>(ny, nx));
a[ny][nx] = a[tmp.second][tmp.first] + 1;
}
}
}
ll ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, a[i][j]); }
}
cout << ans << endl;
} | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
ll GCD(ll a, ll b) {
ll r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
ll LCM(ll a, ll b) {
ll c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
ll Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
return p;
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
return p;
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};
ll h, w;
cin >> h >> w;
vector<string> v(h);
rep(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, -1));
queue<pair<ll, ll>> que;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (v[i][j] == '#') {
a[i][j] = 0;
que.push(pair<ll, ll>(i, j));
}
}
}
while (!que.empty()) {
auto tmp = que.front();
que.pop();
for (ll i = 0; i < 4; i++) {
ll nx = tmp.second + dx[i];
ll ny = tmp.first + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (a[ny][nx] == -1) {
que.push(pair<ll, ll>(ny, nx));
a[ny][nx] = a[tmp.first][tmp.second] + 1;
}
}
}
ll ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, a[i][j]); }
}
cout << ans << endl;
} | [
"expression.operation.binary.change",
"assignment.value.change",
"variable_access.subscript.index.change"
] | 868,741 | 868,740 | u264265458 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
// 方向ベクトル
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
vector<string> board(h);
rep(i, h) { cin >> board[i]; }
vector<vector<int>> matrix(
h, vector<int>(w, -1)); // 数字を書き込むマス。-1で初期化
queue<pair<int, int>> next; // 次に探索するマス目を入れるqueue
rep(i, h) {
rep(j, w) {
if (board[i][j] == '#') {
next.push(make_pair(i, j)); // queueに黒マスを入れる
matrix[i][j] = 0; // 黒マスを0にする
}
}
}
while (!next.empty()) { // nextが空になるまで探索
int x = next.front().first;
int y = next.front().second;
// 4方向調べる
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
// 盤外または探索済みのところはダメ
if (nx < 0 || h <= nx || ny < 0 || w <= ny || matrix[nx][ny] >= 0) {
continue;
}
matrix[nx][ny] = matrix[x][y] + 1; // 隣接マスに1足す
next.push(make_pair(nx, ny)); // 隣接マスをnextに入れる
}
next.pop(); // nextからいま探索したマスを削除
}
int ans = 0;
rep(i, h) {
rep(j, h) { ans = max(ans, matrix[i][j]); }
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
// 方向ベクトル
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
vector<string> board(h);
rep(i, h) { cin >> board[i]; }
vector<vector<int>> matrix(
h, vector<int>(w, -1)); // 数字を書き込むマス。-1で初期化
queue<pair<int, int>> next; // 次に探索するマス目を入れるqueue
rep(i, h) {
rep(j, w) {
if (board[i][j] == '#') {
next.push(make_pair(i, j)); // queueに黒マスを入れる
matrix[i][j] = 0; // 黒マスを0にする
}
}
}
while (!next.empty()) { // nextが空になるまで探索
int x = next.front().first;
int y = next.front().second;
// 4方向調べる
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
// 盤外または探索済みのところはダメ
if (nx < 0 || h <= nx || ny < 0 || w <= ny || matrix[nx][ny] >= 0) {
continue;
}
matrix[nx][ny] = matrix[x][y] + 1; // 隣接マスに1足す
next.push(make_pair(nx, ny)); // 隣接マスをnextに入れる
}
next.pop(); // nextからいま探索したマスを削除
}
int ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, matrix[i][j]); }
}
cout << ans << endl;
return 0;
} | [] | 868,742 | 868,743 | u828388155 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, m, n) for (int i = m; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
#define RREP(i, m, n) for (int i = n; i >= m; --i)
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using namespace std;
const long long MOD = 998244353;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
string *s = new string[h];
rep(i, h) cin >> s[i];
queue<pii> pre, next;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '#') {
pre.push(pii(i, j));
}
}
}
int ans = 0;
while (!pre.empty()) {
while (!pre.empty()) {
int x = pre.front().first;
int y = pre.front().second;
if (x != 0 && s[x - 1][y] != '#') {
s[x - 1][y] = '#';
next.push(pii(x - 1, y));
}
if (x != w - 1 && s[x + 1][y] != '#') {
s[x + 1][y] = '#';
next.push(pii(x + 1, y));
}
if (y != 0 && s[x][y - 1] != '#') {
s[x][y - 1] = '#';
next.push(pii(x, y - 1));
}
if (y != h - 1 && s[x][y + 1] != '#') {
s[x][y + 1] = '#';
next.push(pii(x, y + 1));
}
pre.pop();
}
swap(pre, next);
++ans;
}
cout << ans - 1 << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, m, n) for (int i = m; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
#define RREP(i, m, n) for (int i = n; i >= m; --i)
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using namespace std;
const long long MOD = 998244353;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
string *s = new string[h];
rep(i, h) cin >> s[i];
queue<pii> pre, next;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '#') {
pre.push(pii(i, j));
}
}
}
int ans = 0;
while (!pre.empty()) {
while (!pre.empty()) {
int x = pre.front().first;
int y = pre.front().second;
if (x != 0 && s[x - 1][y] != '#') {
s[x - 1][y] = '#';
next.push(pii(x - 1, y));
}
if (x != h - 1 && s[x + 1][y] != '#') {
s[x + 1][y] = '#';
next.push(pii(x + 1, y));
}
if (y != 0 && s[x][y - 1] != '#') {
s[x][y - 1] = '#';
next.push(pii(x, y - 1));
}
if (y != w - 1 && s[x][y + 1] != '#') {
s[x][y + 1] = '#';
next.push(pii(x, y + 1));
}
pre.pop();
}
swap(pre, next);
++ans;
}
cout << ans - 1 << "\n";
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 868,753 | 868,754 | u020230257 | cpp |
p03053 | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const int IINF = 1 << 30;
vector<vector<int>> dist(1010, vector<int>(1010, IINF));
map<pair<int, int>, bool> visited;
vector<string> g;
int h, w;
bool is_valid(int y, int x) {
return 0 <= y && y < h && 0 <= x && x < w && g[y][x] != '#';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> w;
g.resize(h);
rep(i, h) { cin >> g[i]; }
deque<pair<int, int>> que;
rep(i, h) rep(j, w) {
if (g[i][j] == '#') {
que.push_back({i, j});
dist[i][j] = 0;
}
}
int ans = 0;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
while (!que.empty()) {
deque<pair<int, int>> next;
while (!que.empty()) {
auto cur = que.front();
que.pop_front();
int y = cur.first;
int x = cur.second;
rep(i, 4) {
int ny = y + dy[i];
int nx = x + dx[i];
if (is_valid(ny, nx) && dist[ny][nx] != IINF) {
next.push_back({ny, nx});
dist[ny][nx] = dist[y][x] + 1;
ans = max(ans, dist[ny][nx]);
}
}
}
que = next;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const int IINF = 1 << 30;
vector<vector<int>> dist(1010, vector<int>(1010, IINF));
map<pair<int, int>, bool> visited;
vector<string> g;
int h, w;
bool is_valid(int y, int x) {
return 0 <= y && y < h && 0 <= x && x < w && g[y][x] != '#';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> w;
g.resize(h);
rep(i, h) { cin >> g[i]; }
deque<pair<int, int>> que;
rep(i, h) rep(j, w) {
if (g[i][j] == '#') {
que.push_back({i, j});
dist[i][j] = 0;
}
}
int ans = 0;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
while (!que.empty()) {
deque<pair<int, int>> next;
while (!que.empty()) {
auto cur = que.front();
que.pop_front();
int y = cur.first;
int x = cur.second;
rep(i, 4) {
int ny = y + dy[i];
int nx = x + dx[i];
if (is_valid(ny, nx) && dist[ny][nx] == IINF) {
next.push_back({ny, nx});
dist[ny][nx] = dist[y][x] + 1;
ans = max(ans, dist[ny][nx]);
}
}
}
que = next;
}
cout << ans << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 868,755 | 868,756 | u174404613 | cpp |
p03053 | #include <iostream>
#include <queue>
using namespace std;
const int MAX_N = 1e3 + 5;
int dist[MAX_N][MAX_N];
int ni[4] = {1, 0, -1, 0};
int nj[4] = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pair<int, int>> zeros;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char c;
cin >> c;
if (c == '#') {
zeros.push_back(make_pair(i, j));
}
}
}
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
dist[i][j] = -1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dist[i][j] = 1e9;
}
}
queue<pair<int, int>> Q;
for (auto pr : zeros) {
Q.push(pr);
dist[pr.first][pr.second] = 0;
}
int ans = 0;
while (!Q.empty()) {
pair<int, int> qtop = Q.front();
Q.pop();
int r = qtop.first;
int c = qtop.second;
ans = max(ans, dist[r][c]);
for (int k = 0; k < 4; k++) {
if (dist[r + ni[k]][c + nj[k]] > dist[r][c] + 1) {
dist[r + ni[k]][c + nj[k]] = dist[r][c] + 1;
Q.push(make_pair(r + ni[k], c + nj[k]));
}
}
}
cout << ans << endl;
}
| #include <iostream>
#include <queue>
using namespace std;
const int MAX_N = 1e3 + 5;
int dist[MAX_N][MAX_N];
int ni[4] = {1, 0, -1, 0};
int nj[4] = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pair<int, int>> zeros;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
if (c == '#') {
zeros.push_back(make_pair(i, j));
}
}
}
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
dist[i][j] = -1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dist[i][j] = 1e9;
}
}
queue<pair<int, int>> Q;
for (auto pr : zeros) {
Q.push(pr);
dist[pr.first][pr.second] = 0;
}
int ans = 0;
while (!Q.empty()) {
pair<int, int> qtop = Q.front();
Q.pop();
int r = qtop.first;
int c = qtop.second;
ans = max(ans, dist[r][c]);
for (int k = 0; k < 4; k++) {
if (dist[r + ni[k]][c + nj[k]] > dist[r][c] + 1) {
dist[r + ni[k]][c + nj[k]] = dist[r][c] + 1;
Q.push(make_pair(r + ni[k], c + nj[k]));
}
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 868,784 | 868,785 | u882575405 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;
// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
point_t res;
res.first = lhs.first + rhs.first;
res.second = lhs.second + rhs.second;
return res;
}
//範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
int c = point.first;
int r = point.second;
return ((c >= 0 && c < col) && (r >= 0 && r < row));
}
//配列要素の最大値
int max_v(vector<vector<int>> &v) {
int res = v.at(0).at(0);
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.at(0).size(); j++) {
res = max(res, v.at(i).at(j));
}
}
return res;
}
//多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
while (!que.empty()) {
point_t cur = que.front();
que.pop();
int col_cur = cur.first;
int row_cur = cur.second;
for (const auto &p : points) {
point_t next = cur + p;
int col_next = next.first;
int row_next = next.second;
if (is_in_field(H, W, next)) {
if (v.at(col_next).at(row_next) == -1) {
v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
que.push(next);
}
}
}
}
return max_v(v);
}
int main() {
//入力
int H, W;
cin >> H >> W;
field_t A(H, vector<char>(W));
queue<point_t> que;
vector<vector<int>> v(W, vector<int>(H, -1)); //訪問までに必要な回数
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A.at(i).at(j);
if (A.at(i).at(j) == '#') {
que.push({i, j}); //開始位置の代入
v.at(i).at(j) = 0; //開始位置の訪問回数を0に
}
}
}
//出力
cout << solve(H, W, que, v) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;
// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
point_t res;
res.first = lhs.first + rhs.first;
res.second = lhs.second + rhs.second;
return res;
}
//範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
int c = point.first;
int r = point.second;
return ((c >= 0 && c < col) && (r >= 0 && r < row));
}
//配列要素の最大値
int max_v(vector<vector<int>> &v) {
int res = v.at(0).at(0);
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.at(0).size(); j++) {
res = max(res, v.at(i).at(j));
}
}
return res;
}
//多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
while (!que.empty()) {
point_t cur = que.front();
que.pop();
int col_cur = cur.first;
int row_cur = cur.second;
for (const auto &p : points) {
point_t next = cur + p;
int col_next = next.first;
int row_next = next.second;
if (is_in_field(H, W, next)) {
if (v.at(col_next).at(row_next) == -1) {
v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
que.push(next);
}
}
}
}
return max_v(v);
}
int main() {
//入力
int H, W;
cin >> H >> W;
field_t A(H, vector<char>(W));
queue<point_t> que;
vector<vector<int>> v(H, vector<int>(W, -1)); //訪問までに必要な回数
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A.at(i).at(j);
if (A.at(i).at(j) == '#') {
que.push({i, j}); //開始位置の代入
v.at(i).at(j) = 0; //開始位置の訪問回数を0に
}
}
}
//出力
cout << solve(H, W, que, v) << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 868,799 | 868,800 | u115927976 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;
// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
point_t res;
res.first = lhs.first + rhs.first;
res.second = lhs.second + rhs.second;
return res;
}
//範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
int c = point.first;
int r = point.second;
return ((c >= 0 && c < col) && (r >= 0 && r < row));
}
//配列の最大値
int max_v(vector<vector<int>> &v) {
int res = v.at(0).at(0);
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.at(0).size(); j++) {
res = max(res, v.at(i).at(j));
}
}
return res;
}
//多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
while (!que.empty()) {
point_t cur = que.front();
que.pop();
int col_cur = cur.first;
int row_cur = cur.second;
for (const auto &p : points) {
point_t next = cur + p;
int col_next = next.first;
int row_next = next.second;
if (is_in_field(H, W, next)) {
if (v.at(col_next).at(row_next) == -1) {
v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
que.push(next);
}
}
}
}
return max_v(v);
}
int main() {
//入力
int H, W;
cin >> H >> W;
field_t A(H, vector<char>(W));
queue<point_t> que;
vector<vector<int>> v(W, vector<int>(H, -1)); //訪問までに必要な回数
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A.at(i).at(j);
if (A.at(i).at(j) == '#') {
que.push({i, j}); //開始位置の代入
v.at(i).at(j) = 0; //開始位置の訪問回数を0に
}
}
}
//出力
cout << solve(H, W, que, v) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;
// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
point_t res;
res.first = lhs.first + rhs.first;
res.second = lhs.second + rhs.second;
return res;
}
//範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
int c = point.first;
int r = point.second;
return ((c >= 0 && c < col) && (r >= 0 && r < row));
}
//配列要素の最大値
int max_v(vector<vector<int>> &v) {
int res = v.at(0).at(0);
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.at(0).size(); j++) {
res = max(res, v.at(i).at(j));
}
}
return res;
}
//多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
while (!que.empty()) {
point_t cur = que.front();
que.pop();
int col_cur = cur.first;
int row_cur = cur.second;
for (const auto &p : points) {
point_t next = cur + p;
int col_next = next.first;
int row_next = next.second;
if (is_in_field(H, W, next)) {
if (v.at(col_next).at(row_next) == -1) {
v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
que.push(next);
}
}
}
}
return max_v(v);
}
int main() {
//入力
int H, W;
cin >> H >> W;
field_t A(H, vector<char>(W));
queue<point_t> que;
vector<vector<int>> v(H, vector<int>(W, -1)); //訪問までに必要な回数
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A.at(i).at(j);
if (A.at(i).at(j) == '#') {
que.push({i, j}); //開始位置の代入
v.at(i).at(j) = 0; //開始位置の訪問回数を0に
}
}
}
//出力
cout << solve(H, W, que, v) << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change",
"control_flow.return.add",
"control_flow.return.0.add"
] | 868,802 | 868,800 | u115927976 | cpp |
p03053 | #include <cstdio>
#include <queue>
#include <tuple>
using namespace std;
int main(int argc, char const *argv[]) {
int h, w;
scanf("%d %d\n", h, w);
char maze[h][w + 1];
for (int i = 0; i < h; i++) {
scanf("%s\n", maze[i]);
}
int ans = 0;
queue<tuple<int, int, int>> que;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (maze[i][j] == '#')
que.push(make_tuple(i, j, 0));
}
}
int dxy[] = {0, 1, 0, -1, 0};
while (!que.empty()) {
int x, y, d;
tie(x, y, d) = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int nx = x + dxy[i];
int ny = y + dxy[i + 1];
if (nx < 0 || h <= nx || ny < 0 || w <= ny)
continue;
else if (maze[nx][ny] == '.') {
maze[nx][ny] = '#';
que.push(make_tuple(nx, ny, d + 1));
ans = d + 1;
}
}
}
printf("%d\n", ans);
return 0;
}
| #include <cstdio>
#include <queue>
#include <tuple>
using namespace std;
int main(int argc, char const *argv[]) {
int h, w;
scanf("%d %d\n", &h, &w);
char maze[h][w + 1];
for (int i = 0; i < h; i++) {
scanf("%s\n", maze[i]);
}
int ans = 0;
queue<tuple<int, int, int>> que;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (maze[i][j] == '#')
que.push(make_tuple(i, j, 0));
}
}
int dxy[] = {0, 1, 0, -1, 0};
while (!que.empty()) {
int x, y, d;
tie(x, y, d) = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int nx = x + dxy[i];
int ny = y + dxy[i + 1];
if (nx < 0 || h <= nx || ny < 0 || w <= ny)
continue;
else if (maze[nx][ny] == '.') {
maze[nx][ny] = '#';
que.push(make_tuple(nx, ny, d + 1));
ans = d + 1;
}
}
}
printf("%d\n", ans);
return 0;
}
| [
"expression.operation.unary.reference.add"
] | 868,807 | 868,808 | u445784649 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int main() {
long H, W;
cin >> H >> W;
vector<vector<long>> data(H, vector<long>(W, INT_MAX));
char a;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a;
if (a == '#')
data.at(i).at(j) = 0;
}
}
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
data.at(i).at(j) = min(data.at(i).at(j - 1) + 1, data.at(i).at(j));
}
for (int j = W - 2; j >= 0; j--) {
data.at(i).at(j) = min(data.at(i).at(j + 1) + 1, data.at(i).at(j));
}
}
for (int i = 0; i < W; i++) {
for (int j = 1; j < W; j++) {
data.at(j).at(i) = min(data.at(j - 1).at(i) + 1, data.at(j).at(i));
}
for (int j = H - 2; j >= 0; j--) {
data.at(j).at(i) = min(data.at(j + 1).at(i) + 1, data.at(j).at(i));
}
}
long ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, data.at(i).at(j));
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long H, W;
cin >> H >> W;
vector<vector<long>> data(H, vector<long>(W, INT_MAX));
char a;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a;
if (a == '#')
data.at(i).at(j) = 0;
}
}
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
data.at(i).at(j) = min(data.at(i).at(j - 1) + 1, data.at(i).at(j));
}
for (int j = W - 2; j >= 0; j--) {
data.at(i).at(j) = min(data.at(i).at(j + 1) + 1, data.at(i).at(j));
}
}
for (int i = 0; i < W; i++) {
for (int j = 1; j < H; j++) {
data.at(j).at(i) = min(data.at(j - 1).at(i) + 1, data.at(j).at(i));
}
for (int j = H - 2; j >= 0; j--) {
data.at(j).at(i) = min(data.at(j + 1).at(i) + 1, data.at(j).at(i));
}
}
long ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, data.at(i).at(j));
}
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 868,809 | 868,810 | u239087789 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)
/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vvpii = vector<pii>;
using mii = map<int, int>;
using vs = vector<string>;
using vb = vector<bool>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* iostream */
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> istream &operator>>(istream &is, pair<T, T> &p) {
int a, b;
is >> a >> b;
p = mp(a, b);
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> istream &operator>>(istream &is, complex<T> &c) {
T x, y;
is >> x >> y;
c = complex<T>(x, y);
return is;
}
/* input */
#define _overload(_1, _2, _3, _4, _5, _6, name, ...) name
#define _g1(a) \
int a; \
cin >> a;
#define _g2(a, b) \
int a, b; \
cin >> a >> b;
#define _g3(a, b, c) \
int a, b, c; \
cin >> a >> b >> c;
#define _g4(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d;
#define _g5(a, b, c, d, e) \
int a, b, c, d, e; \
cin >> a >> b >> c >> d >> e;
#define _g6(a, b, c, d, e, f) \
int a, b, c, d, e, f; \
cin >> a >> b >> c >> d >> e >> f;
#define in(...) \
_overload(__VA_ARGS__, _g6, _g5, _g4, _g3, _g2, _g1)(__VA_ARGS__)
/* debug */
#define _pp_overload(_1, _2, _3, _4, _5, _6, name, ...) name
#define _p1(a) cerr << #a "=" << (a) << endl;
#define _p2(a, b) cerr << #a "=" << (a) << "," #b "=" << (b) << endl;
#define _p3(a, b, c) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) << endl;
#define _p4(a, b, c, d) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << endl;
#define _p5(a, b, c, d, e) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << "," #e "=" << (e) << endl;
#define _p6(a, b, c, d, e, f) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << "," #e "=" << (e) << "," #f "=" << (f) << endl;
#define pp(...) \
_pp_overload(__VA_ARGS__, _p6, _p5, _p4, _p3, _p2, _p1)(__VA_ARGS__)
/* const */
// const int INF = 1001001001;
const ll INF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
/* func */
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline bool odd(int x) { return x % 2 == 1; }
inline bool even(int x) { return x % 2 == 0; }
inline int sum(vi a) { return accumulate(ALL(a), 0); }
inline void yn(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
inline void YN(bool ans) { cout << (ans ? "YES" : "NO") << endl; }
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
template <class T> T gcd(const T &a, const T &b) {
return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template <class T> T div_ceil(const T &a, const T &b) {
return (a + b - 1) / b;
}
template <class T> bool by_snd(const T &a, const T &b) { return a.snd < b.snd; }
inline void print_and_exit(int x) {
cout << x << endl;
exit(0);
}
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
// #define int long long
signed main() {
in(w, h);
vector<string> a(h);
cin >> a;
// 黒マスをqueueに保存。操作回数ゼロ回とする
vvi seen(h, vi(w, -1));
queue<pii> que;
rep(i, h) rep(j, w) if (a[i][j] == '#') {
que.push(make_pair(i, j));
seen[i][j] = 0;
}
// BFS
while (!que.empty()) {
int x, y;
tie(x, y) = que.front();
que.pop();
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!inside(nx, ny, h, w))
continue;
if (seen[nx][ny] != -1)
continue;
seen[nx][ny] = seen[x][y] + 1;
que.push(make_pair(nx, ny));
}
}
int ans = 0;
rep(i, h) rep(j, w) chmax(ans, seen[i][j]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)
/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vvpii = vector<pii>;
using mii = map<int, int>;
using vs = vector<string>;
using vb = vector<bool>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* iostream */
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> istream &operator>>(istream &is, pair<T, T> &p) {
int a, b;
is >> a >> b;
p = mp(a, b);
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> istream &operator>>(istream &is, complex<T> &c) {
T x, y;
is >> x >> y;
c = complex<T>(x, y);
return is;
}
/* input */
#define _overload(_1, _2, _3, _4, _5, _6, name, ...) name
#define _g1(a) \
int a; \
cin >> a;
#define _g2(a, b) \
int a, b; \
cin >> a >> b;
#define _g3(a, b, c) \
int a, b, c; \
cin >> a >> b >> c;
#define _g4(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d;
#define _g5(a, b, c, d, e) \
int a, b, c, d, e; \
cin >> a >> b >> c >> d >> e;
#define _g6(a, b, c, d, e, f) \
int a, b, c, d, e, f; \
cin >> a >> b >> c >> d >> e >> f;
#define in(...) \
_overload(__VA_ARGS__, _g6, _g5, _g4, _g3, _g2, _g1)(__VA_ARGS__)
/* debug */
#define _pp_overload(_1, _2, _3, _4, _5, _6, name, ...) name
#define _p1(a) cerr << #a "=" << (a) << endl;
#define _p2(a, b) cerr << #a "=" << (a) << "," #b "=" << (b) << endl;
#define _p3(a, b, c) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) << endl;
#define _p4(a, b, c, d) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << endl;
#define _p5(a, b, c, d, e) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << "," #e "=" << (e) << endl;
#define _p6(a, b, c, d, e, f) \
cerr << #a "=" << (a) << "," #b "=" << (b) << "," #c "=" << (c) \
<< "," #d "=" << (d) << "," #e "=" << (e) << "," #f "=" << (f) << endl;
#define pp(...) \
_pp_overload(__VA_ARGS__, _p6, _p5, _p4, _p3, _p2, _p1)(__VA_ARGS__)
/* const */
// const int INF = 1001001001;
const ll INF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
/* func */
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {
return y >= 0 && x >= 0 && y < H && x < W;
}
inline bool odd(int x) { return x % 2 == 1; }
inline bool even(int x) { return x % 2 == 0; }
inline int sum(vi a) { return accumulate(ALL(a), 0); }
inline void yn(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
inline void YN(bool ans) { cout << (ans ? "YES" : "NO") << endl; }
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
template <class T> T gcd(const T &a, const T &b) {
return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template <class T> T div_ceil(const T &a, const T &b) {
return (a + b - 1) / b;
}
template <class T> bool by_snd(const T &a, const T &b) { return a.snd < b.snd; }
inline void print_and_exit(int x) {
cout << x << endl;
exit(0);
}
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
// #define int long long
signed main() {
in(h, w);
vector<string> a(h);
cin >> a;
// 黒マスをqueueに保存。操作回数ゼロ回とする
vvi seen(h, vi(w, -1));
queue<pii> que;
rep(i, h) rep(j, w) if (a[i][j] == '#') {
que.push(make_pair(i, j));
seen[i][j] = 0;
}
// BFS
while (!que.empty()) {
int x, y;
tie(x, y) = que.front();
que.pop();
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (!inside(nx, ny, h, w))
continue;
if (seen[nx][ny] != -1)
continue;
seen[nx][ny] = seen[x][y] + 1;
que.push(make_pair(nx, ny));
}
}
int ans = 0;
rep(i, h) rep(j, w) chmax(ans, seen[i][j]);
cout << ans << endl;
}
| [
"call.arguments.change",
"call.arguments.add"
] | 868,816 | 868,817 | u106964380 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
#define vec2(a, y, x) vector<vector<char>> a(y, vector<char>(x))
#define vec1(a, n) \
vector<int> a(n); \
rep(i, n) cin >> a[i]
vector<int> ta = {1, 0, -1, 0};
vector<int> su = {0, 1, 0, -1};
using p = pair<int, int>;
int main() {
int h, w, x, y, nx, ny;
cin >> h >> w;
vec2(a, h, w);
rep(i, h) rep(j, w) cin >> a[i][j];
queue<p> bfs;
vector<vector<int>> seen(h, vector<int>(w, 10000000));
rep(i, h) rep(j, w) if (a[i][j] == '#') {
bfs.push(p(i, j));
seen[i][j] = 0;
}
while (!bfs.empty()) {
y = bfs.front().first;
x = bfs.front().second;
bfs.pop();
rep(i, 4) {
ny = y + ta[i];
nx = x + su[i];
if (ny < 0 || nx < 0 || nx >= w || ny >= h)
continue;
if (a[ny][nx] == '#')
continue;
a[ny][nx] = '#';
seen[ny][nx] = seen[y][x] + 1;
bfs.push(p(ny, nx));
}
}
int maxi = seen[0][0];
rep(i, h) rep(j, w) { maxi = min(maxi, seen[i][j]); }
cout << maxi << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
#define vec2(a, y, x) vector<vector<char>> a(y, vector<char>(x))
#define vec1(a, n) \
vector<int> a(n); \
rep(i, n) cin >> a[i]
vector<int> ta = {1, 0, -1, 0};
vector<int> su = {0, 1, 0, -1};
using p = pair<int, int>;
int main() {
int h, w, x, y, nx, ny;
cin >> h >> w;
vec2(a, h, w);
rep(i, h) rep(j, w) cin >> a[i][j];
queue<p> bfs;
vector<vector<int>> seen(h, vector<int>(w, 10000000));
rep(i, h) rep(j, w) if (a[i][j] == '#') {
bfs.push(p(i, j));
seen[i][j] = 0;
}
while (!bfs.empty()) {
y = bfs.front().first;
x = bfs.front().second;
bfs.pop();
rep(i, 4) {
ny = y + ta[i];
nx = x + su[i];
if (ny < 0 || nx < 0 || nx >= w || ny >= h)
continue;
if (a[ny][nx] == '#')
continue;
a[ny][nx] = '#';
seen[ny][nx] = seen[y][x] + 1;
bfs.push(p(ny, nx));
}
}
int maxi = seen[0][0];
rep(i, h) rep(j, w) { maxi = max(maxi, seen[i][j]); }
cout << maxi << endl;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 868,824 | 868,825 | u424602097 | cpp |
p03053 | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
{ cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond &&mes)
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;
template <typename T> T round_up(const T &a, const T &b) {
return (a + (b - 1)) / b;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << p.first << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
REP(i, (int)v.size()) is >> v[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, (int)v.size()) os << v[i] << endl;
return os;
}
template <typename T> T clamp(T &n, T a, T b) {
if (n < a)
n = a;
if (n > b)
n = b;
return n;
}
template <typename T> static T GCD(T u, T v) {
T r;
while (v != 0) {
r = u % v;
u = v;
v = r;
}
return u;
}
template <typename T> static T LCM(T u, T v) { return u / GCD(u, v) * v; }
std::vector<int> enum_div(int n) {
std::vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
struct ToUpper {
char operator()(char c) { return toupper(c); }
};
struct ToLower {
char operator()(char c) { return tolower(c); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int H, W;
cin >> H >> W;
vector<vector<int>> field(H, vector<int>(W, -1));
queue<pair<int, int>> q;
REP(h, H) {
string S;
cin >> S;
REP(w, W) {
if (S[w] == '#') {
field[h][w] = 0;
q.push({w, h});
}
}
}
auto solve = [&]() {
int ans = 0;
while (!q.empty()) {
pair<int, int> p = q.front();
q.pop();
if (p.first - 1 >= 0 && field[p.second][p.first - 1] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second][p.first - 1] = n;
chmax(ans, n);
q.push({p.first - 1, p.second});
}
if (p.first + 1 < W && field[p.second][p.first + 1] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second][p.first + 1] = n;
chmax(ans, n);
q.push({p.first + 1, p.second});
}
if (p.second - 1 >= 0 && field[p.second - 1][p.first] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second - 1][p.first] = n;
chmax(ans, n);
q.push({p.first, p.second - 1});
}
if (p.second + 1 < W && field[p.second + 1][p.first] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second + 1][p.first] = n;
chmax(ans, n);
q.push({p.first, p.second + 1});
}
}
return ans;
};
cout << solve() << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
{ cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond &&mes)
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;
template <typename T> T round_up(const T &a, const T &b) {
return (a + (b - 1)) / b;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << p.first << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
REP(i, (int)v.size()) is >> v[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, (int)v.size()) os << v[i] << endl;
return os;
}
template <typename T> T clamp(T &n, T a, T b) {
if (n < a)
n = a;
if (n > b)
n = b;
return n;
}
template <typename T> static T GCD(T u, T v) {
T r;
while (v != 0) {
r = u % v;
u = v;
v = r;
}
return u;
}
template <typename T> static T LCM(T u, T v) { return u / GCD(u, v) * v; }
std::vector<int> enum_div(int n) {
std::vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
struct ToUpper {
char operator()(char c) { return toupper(c); }
};
struct ToLower {
char operator()(char c) { return tolower(c); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int H, W;
cin >> H >> W;
vector<vector<int>> field(H, vector<int>(W, -1));
queue<pair<int, int>> q;
REP(h, H) {
string S;
cin >> S;
REP(w, W) {
if (S[w] == '#') {
field[h][w] = 0;
q.push({w, h});
}
}
}
auto solve = [&]() {
int ans = 0;
while (!q.empty()) {
pair<int, int> p = q.front();
q.pop();
if (p.first - 1 >= 0 && field[p.second][p.first - 1] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second][p.first - 1] = n;
chmax(ans, n);
q.push({p.first - 1, p.second});
}
if (p.first + 1 < W && field[p.second][p.first + 1] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second][p.first + 1] = n;
chmax(ans, n);
q.push({p.first + 1, p.second});
}
if (p.second - 1 >= 0 && field[p.second - 1][p.first] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second - 1][p.first] = n;
chmax(ans, n);
q.push({p.first, p.second - 1});
}
if (p.second + 1 < H && field[p.second + 1][p.first] < 0) {
int n = field[p.second][p.first] + 1;
field[p.second + 1][p.first] = n;
chmax(ans, n);
q.push({p.first, p.second + 1});
}
}
return ans;
};
cout << solve() << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 868,844 | 868,845 | u303039933 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int R, C;
char G[1005][1005];
queue<pair<int, pair<int, int>>> Q;
int dist[1005][1005];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
cin >> R >> C;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cin >> G[i][j];
if (G[i][j] == '#') {
Q.push(make_pair(0, make_pair(i, j)));
}
}
}
memset(dist, -1, sizeof(dist));
while (!Q.empty()) {
int d = Q.front().first, r = Q.front().second.first,
c = Q.front().second.second;
Q.pop();
if (dist[r][c] != -1)
continue;
dist[r][c] = d;
for (int i = 0; i < 4; i++) {
if (r + dx[i] >= 0 && r + dx[i] < R && c + dy[i] >= 0 && c + dy[i] < C) {
Q.push(make_pair(d + 1, make_pair(r + dx[i], c + dy[i])));
}
}
}
int big = -1;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (dist[i][j] > big) {
dist[i][j] = big;
}
}
}
cout << big;
} | #include <bits/stdc++.h>
using namespace std;
int R, C;
char G[1005][1005];
queue<pair<int, pair<int, int>>> Q;
int dist[1005][1005];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
cin >> R >> C;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cin >> G[i][j];
if (G[i][j] == '#') {
Q.push(make_pair(0, make_pair(i, j)));
}
}
}
memset(dist, -1, sizeof(dist));
while (!Q.empty()) {
int d = Q.front().first, r = Q.front().second.first,
c = Q.front().second.second;
Q.pop();
if (dist[r][c] != -1)
continue;
dist[r][c] = d;
for (int i = 0; i < 4; i++) {
if (r + dx[i] >= 0 && r + dx[i] < R && c + dy[i] >= 0 && c + dy[i] < C) {
Q.push(make_pair(d + 1, make_pair(r + dx[i], c + dy[i])));
}
}
}
int big = -1;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (dist[i][j] > big) {
big = dist[i][j];
}
}
}
cout << big;
} | [
"assignment.change"
] | 868,852 | 868,853 | u532047586 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
char board[H][W];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
cin >> board[i][j];
int dis[H][W];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
dis[i][j] = (board[i][j] == '#') ? 0 : H * W;
for (int i = 0; i < H; i++) {
int s = -1;
for (int j = 0; j < W; j++) {
if (board[i][j] == '#')
s = j;
else if (s >= 0)
dis[i][j] = min(dis[i][j], j - s);
}
s = -1;
for (int j = W - 1; j >= 0; j--) {
if (board[i][j] == '#')
s = j;
else if (s >= 0)
dis[i][j] = min(dis[i][j], s - j);
}
}
for (int j = 0; j < W; j++)
for (int i = 1; i < H; i++)
dis[i][j] = min(dis[i - 1][j] + 1, dis[i][j]);
for (int j = 0; j < W; j++)
for (int i = H - 1; i >= 0; i--)
dis[i][j] = min(dis[i + 1][j] + 1, dis[i][j]);
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
ans = max(ans, dis[i][j]);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
char board[H][W];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
cin >> board[i][j];
int dis[H][W];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
dis[i][j] = (board[i][j] == '#') ? 0 : H * W;
int s;
for (int i = 0; i < H; i++) {
s = -1;
for (int j = 0; j < W; j++) {
if (board[i][j] == '#')
s = j;
else if (s >= 0)
dis[i][j] = min(dis[i][j], j - s);
}
s = -1;
for (int j = W - 1; j >= 0; j--) {
if (board[i][j] == '#')
s = j;
else if (s >= 0)
dis[i][j] = min(dis[i][j], s - j);
}
}
for (int j = 0; j < W; j++)
for (int i = 1; i < H; i++)
dis[i][j] = min(dis[i - 1][j] + 1, dis[i][j]);
for (int j = 0; j < W; j++)
for (int i = H - 2; i >= 0; i--)
dis[i][j] = min(dis[i + 1][j] + 1, dis[i][j]);
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
ans = max(ans, dis[i][j]);
cout << ans << endl;
return 0;
} | [
"variable_declaration.add",
"literal.number.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 868,875 | 868,876 | u052247353 | cpp |
p03053 | #include <iostream>
#include <stdio.h>
#include <vector>
int main(int argc, char **argv) {
int H, W;
std::cin >> H;
std::cin >> W;
std::vector<char> A;
std::vector<int> vIndex;
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
char Aij;
std::cin >> Aij;
A.push_back(Aij);
if (Aij == '#') {
vIndex.push_back(h * W + w);
}
}
}
int counter = 0;
int index0, index1, index2, index3;
int S = H * W;
for (int i = 0; i < (int)vIndex.size(); i++) {
bool nochange = true;
int iMax = (int)vIndex.size();
for (; i < iMax; i++) {
index0 = vIndex[i] - 1;
index1 = vIndex[i] + 1;
index2 = vIndex[i] + W;
index3 = vIndex[i] - W;
if (vIndex[i] % W != 0 && A[index0] == '.') {
vIndex.push_back(index0);
A[index0] = '#';
nochange = false;
}
if (vIndex[i] % W != W - 1 && A[index1] == '.') {
vIndex.push_back(index1);
A[index1] = '#';
nochange = false;
}
if (index2 < S && A[index2] == '.') {
vIndex.push_back(index2);
A[index2] = '#';
nochange = false;
}
if (index3 >= 0 && A[index3] == '.') {
vIndex.push_back(index3);
A[index3] = '#';
nochange = false;
}
}
if (nochange) {
break;
}
counter++;
}
std::cout << counter;
return 0;
} | #include <iostream>
#include <stdio.h>
#include <vector>
int main(int argc, char **argv) {
int H, W;
std::cin >> H;
std::cin >> W;
std::vector<char> A;
std::vector<int> vIndex;
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
char Aij;
std::cin >> Aij;
A.push_back(Aij);
if (Aij == '#') {
vIndex.push_back(h * W + w);
}
}
}
int counter = 0;
int index0, index1, index2, index3;
int S = H * W;
for (int i = 0; i < (int)vIndex.size(); i++) {
bool nochange = true;
int iMax = (int)vIndex.size();
for (; i < iMax; i++) {
index0 = vIndex[i] - 1;
index1 = vIndex[i] + 1;
index2 = vIndex[i] + W;
index3 = vIndex[i] - W;
if (vIndex[i] % W != 0 && A[index0] == '.') {
vIndex.push_back(index0);
A[index0] = '#';
nochange = false;
}
if (vIndex[i] % W != W - 1 && A[index1] == '.') {
vIndex.push_back(index1);
A[index1] = '#';
nochange = false;
}
if (index2 < S && A[index2] == '.') {
vIndex.push_back(index2);
A[index2] = '#';
nochange = false;
}
if (index3 >= 0 && A[index3] == '.') {
vIndex.push_back(index3);
A[index3] = '#';
nochange = false;
}
}
if (nochange) {
break;
}
counter++;
i--;
}
std::cout << counter;
return 0;
} | [
"expression.unary.arithmetic.add"
] | 868,881 | 868,882 | u547728054 | cpp |
p03053 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define DEBUG(x) cout << #x << ": " << x << endl
using namespace std;
int main() {
int H, W;
cin >> H >> W;
int A[H + 2][W + 2];
vector<pair<int, int>> v[100002];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char x;
cin >> x;
if (x == '#') {
A[i + 1][j + 1] = 1;
v[0].push_back(make_pair(i + 1, j + 1));
} else
A[i + 1][j + 1] = -1;
}
}
long long i;
for (i = 0; i < 10000002; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (A[v[i][j].first - 1][v[i][j].second] == -1) {
A[v[i][j].first - 1][v[i][j].second] = 1;
if (v[i][j].first - 1 > 0) {
v[i + 1].push_back(make_pair(v[i][j].first - 1, v[i][j].second));
}
}
if (A[v[i][j].first + 1][v[i][j].second] == -1) {
A[v[i][j].first + 1][v[i][j].second] = 1;
if (v[i][j].first + 1 < H) {
v[i + 1].push_back(make_pair(v[i][j].first + 1, v[i][j].second));
}
}
if (A[v[i][j].first][v[i][j].second - 1] == -1) {
A[v[i][j].first][v[i][j].second - 1] = 1;
if (v[i][j].second - 1 > 0) {
v[i + 1].push_back(make_pair(v[i][j].first, v[i][j].second - 1));
}
}
if (A[v[i][j].first][v[i][j].second + 1] == -1) {
A[v[i][j].first][v[i][j].second + 1] = 1;
if (v[i][j].second + 1 < W) {
v[i + 1].push_back(make_pair(v[i][j].first, v[i][j].second + 1));
}
}
}
if (v[i + 1].size() == 0)
break;
}
cout << i << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define DEBUG(x) cout << #x << ": " << x << endl
using namespace std;
int main() {
int H, W;
cin >> H >> W;
int A[H + 2][W + 2];
vector<pair<int, int>> v[100002];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char x;
cin >> x;
if (x == '#') {
A[i + 1][j + 1] = 1;
v[0].push_back(make_pair(i + 1, j + 1));
} else
A[i + 1][j + 1] = -1;
}
}
long long i;
for (i = 0; i < 100002; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (A[v[i][j].first - 1][v[i][j].second] == -1) {
A[v[i][j].first - 1][v[i][j].second] = 1;
if (v[i][j].first - 1 >= 0) {
v[i + 1].push_back(make_pair(v[i][j].first - 1, v[i][j].second));
}
}
if (A[v[i][j].first + 1][v[i][j].second] == -1) {
A[v[i][j].first + 1][v[i][j].second] = 1;
if (v[i][j].first + 1 <= H) {
v[i + 1].push_back(make_pair(v[i][j].first + 1, v[i][j].second));
}
}
if (A[v[i][j].first][v[i][j].second - 1] == -1) {
A[v[i][j].first][v[i][j].second - 1] = 1;
if (v[i][j].second - 1 >= 0) {
v[i + 1].push_back(make_pair(v[i][j].first, v[i][j].second - 1));
}
}
if (A[v[i][j].first][v[i][j].second + 1] == -1) {
A[v[i][j].first][v[i][j].second + 1] = 1;
if (v[i][j].second + 1 <= W) {
v[i + 1].push_back(make_pair(v[i][j].first, v[i][j].second + 1));
}
}
}
if (v[i + 1].size() == 0)
break;
}
cout << i << endl;
return 0;
}
| [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 868,883 | 868,884 | u574045761 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
int main() {
int H, W;
int int_max = 10000;
std::vector<std::string> A;
std::vector<std::vector<std::vector<int>>> dp;
std::cin >> H >> W;
A = std::vector<std::string>(H, " ");
dp = std::vector<std::vector<std::vector<int>>>(
5, std::vector<std::vector<int>>(H, std::vector<int>(W, int_max)));
for (int h = 0; h < H; h++) {
std::cin >> A[h];
}
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
dp[0][h][w] = std::min(h != 0 ? dp[0][h - 1][w] : int_max,
w != 0 ? dp[0][h][w - 1] : int_max) +
1;
dp[1][h][W - 1 - w] = std::min(h != 0 ? dp[1][h - 1][W - 1 - w] : int_max,
w != 0 ? dp[1][h][W - w] : int_max) +
1;
dp[2][H - 1 - h][w] =
std::min(h != 0 ? dp[2][H - h][w] : int_max,
w != 0 ? dp[2][H - 1 - h][w - 1] : int_max) +
1;
dp[3][H - 1 - h][W - 1 - w] =
std::min(h != 0 ? dp[3][H - h][W - 1 - w] : int_max,
w != 0 ? dp[3][H - 1 - h][w + 1] : int_max) +
1;
if (A[h][w] == '#')
dp[0][h][w] = 0;
if (A[h][W - 1 - w] == '#')
dp[1][h][W - 1 - w] = 0;
if (A[H - 1 - h][w] == '#')
dp[2][H - 1 - h][w] = 0;
if (A[H - 1 - h][W - 1 - w] == '#')
dp[3][H - 1 - h][W - 1 - w] = 0;
// std::cout << dp[0][h][w] << " " << dp[1][h][W-1-w] << " " <<
// dp[2][H-1-h][w] << " " << dp[3][H-1-h][W-1-w] << " " << std::endl;
}
}
int res = 0;
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
dp[4][h][w] =
std::min({dp[0][h][w], dp[1][h][w], dp[2][h][w], dp[3][h][w]});
if (dp[4][h][w] != int_max && res < dp[4][h][w])
res = dp[4][h][w];
}
}
std::cout << res << std::endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
int main() {
int H, W;
int int_max = 10000;
std::vector<std::string> A;
std::vector<std::vector<std::vector<int>>> dp;
std::cin >> H >> W;
A = std::vector<std::string>(H, " ");
dp = std::vector<std::vector<std::vector<int>>>(
5, std::vector<std::vector<int>>(H, std::vector<int>(W, int_max)));
for (int h = 0; h < H; h++) {
std::cin >> A[h];
}
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
dp[0][h][w] = std::min(h != 0 ? dp[0][h - 1][w] : int_max,
w != 0 ? dp[0][h][w - 1] : int_max) +
1;
dp[1][h][W - 1 - w] = std::min(h != 0 ? dp[1][h - 1][W - 1 - w] : int_max,
w != 0 ? dp[1][h][W - w] : int_max) +
1;
dp[2][H - 1 - h][w] =
std::min(h != 0 ? dp[2][H - h][w] : int_max,
w != 0 ? dp[2][H - 1 - h][w - 1] : int_max) +
1;
dp[3][H - 1 - h][W - 1 - w] =
std::min(h != 0 ? dp[3][H - h][W - 1 - w] : int_max,
w != 0 ? dp[3][H - 1 - h][W - w] : int_max) +
1;
if (A[h][w] == '#')
dp[0][h][w] = 0;
if (A[h][W - 1 - w] == '#')
dp[1][h][W - 1 - w] = 0;
if (A[H - 1 - h][w] == '#')
dp[2][H - 1 - h][w] = 0;
if (A[H - 1 - h][W - 1 - w] == '#')
dp[3][H - 1 - h][W - 1 - w] = 0;
}
}
int res = 0;
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
dp[4][h][w] =
std::min({dp[0][h][w], dp[1][h][w], dp[2][h][w], dp[3][h][w]});
if (dp[4][h][w] < int_max && res < dp[4][h][w])
res = dp[4][h][w];
}
}
std::cout << res << std::endl;
return 0;
} | [
"assignment.change",
"expression.operation.binary.remove",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 868,898 | 868,899 | u005702636 | cpp |
p03053 | #include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1 << 30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
int ans = 0;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
cin >> H >> W;
vector<vector<char>> a(H + 1, vector<char>(W + 1));
vector<vector<int>> b(H + 1, vector<int>(W + 1, 0));
vector<pair<int, int>> init;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> a[i][j];
if (a[i][j] == '#')
init.push_back(make_pair(i, j));
}
}
N = init.size();
auto c = [&b](pair<int, int> l, pair<int, int> r) {
return b[l.first][l.second] > b[r.first][r.second];
};
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(c)> q(c);
vector<int> len(N, 0);
for (int i = 0; i < N; i++) {
b[init[i].first][init[i].second] = -1;
q.push(init[i]);
}
bool flag = 1;
while (!q.empty()) {
pair<int, int> tmp = q.top();
q.pop();
// cout << b[tmp.first][tmp.second] << endl;
for (int j = 0; j < 4; j++) {
int x = tmp.first + dx[j];
int y = tmp.second + dy[j];
if (x > 0 && x < W + 1 && y > 0 && y < H + 1 && b[x][y] == 0) {
if (b[tmp.first][tmp.second] == -1)
b[x][y] = 1;
else
b[x][y] = b[tmp.first][tmp.second] + 1;
q.push(make_pair(x, y));
}
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
ans = max(ans, b[i][j]);
}
}
if (ans == -1)
ans = 0;
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1 << 30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
int ans = 0;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
cin >> H >> W;
vector<vector<char>> a(H + 1, vector<char>(W + 1));
vector<vector<int>> b(H + 1, vector<int>(W + 1, 0));
vector<pair<int, int>> init;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> a[i][j];
if (a[i][j] == '#')
init.push_back(make_pair(i, j));
}
}
N = init.size();
auto c = [&b](pair<int, int> l, pair<int, int> r) {
return b[l.first][l.second] > b[r.first][r.second];
};
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(c)> q(c);
vector<int> len(N, 0);
for (int i = 0; i < N; i++) {
b[init[i].first][init[i].second] = -1;
q.push(init[i]);
}
bool flag = 1;
while (!q.empty()) {
pair<int, int> tmp = q.top();
q.pop();
// cout << b[tmp.first][tmp.second] << endl;
for (int j = 0; j < 4; j++) {
int x = tmp.first + dx[j];
int y = tmp.second + dy[j];
// cout << tmp.first << tmp.second << endl;
if (x > 0 && x < H + 1 && y > 0 && y < W + 1 && b[x][y] == 0) {
if (b[tmp.first][tmp.second] == -1)
b[x][y] = 1;
else
b[x][y] = b[tmp.first][tmp.second] + 1;
q.push(make_pair(x, y));
}
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
ans = max(ans, b[i][j]);
// cout << b[i][j] << endl;
}
}
if (ans == -1)
ans = 0;
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 868,900 | 868,901 | u030090262 | cpp |
p03053 | #include <iostream>
#include <queue>
using namespace std;
static const int MAX = 1002;
typedef pair<int, int> P;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool used[MAX][MAX] = {};
int H, W;
char a[MAX][MAX];
int bfs() {
queue<P> que;
queue<int> num;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (a[i][j] == '#') {
que.push(P(i, j));
used[i][j] = true;
num.push(0);
}
}
}
int cnt = 0;
while (!que.empty()) {
P p = que.front();
que.pop();
cnt = num.front();
num.pop();
for (int i = 0; i < 4; i++) {
int nx = p.first + dx[i];
int ny = p.second + dy[i];
if (nx >= 0 && ny > 0 && nx < H && ny < W && used[nx][ny] == false) {
que.push(P(nx, ny));
used[nx][ny] = true;
num.push(cnt + 1);
}
}
}
return cnt;
}
int main() {
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a[i][j];
}
}
int ans = bfs();
cout << ans << endl;
} | #include <iostream>
#include <queue>
using namespace std;
static const int MAX = 1002;
typedef pair<int, int> P;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool used[MAX][MAX] = {};
int H, W;
char a[MAX][MAX];
int bfs() {
queue<P> que;
queue<int> num;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (a[i][j] == '#') {
que.push(P(i, j));
used[i][j] = true;
num.push(0);
}
}
}
int cnt = 0;
while (!que.empty()) {
P p = que.front();
que.pop();
cnt = num.front();
num.pop();
for (int i = 0; i < 4; i++) {
int nx = p.first + dx[i];
int ny = p.second + dy[i];
if (nx >= 0 && ny >= 0 && nx < H && ny < W && used[nx][ny] == false) {
que.push(P(nx, ny));
used[nx][ny] = true;
num.push(cnt + 1);
}
}
}
return cnt;
}
int main() {
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a[i][j];
}
}
int ans = bfs();
cout << ans << endl;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 868,925 | 868,926 | u660341491 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define CHMAX(a, b) a = std::max(a, b)
#define CHMIN(a, b) a = std::min(a, b)
#define CHABS(a) a = std::abs(a)
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for (lli i = 0; i < n; i++)
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
lli mod197 = 1000000007LL;
// ax + by = gcd(a,b) 最大公約数
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
lli visited[1002][1002] = {};
int main(void) {
lli H, W;
cin >> H >> W;
std::queue<tlll> q;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c;
cin >> c;
if (c == '#') {
q.push(tlll{i + 1, j + 1, 1});
}
}
}
for (int i = 1; i <= H; i++) {
visited[i][W + 1] = 1;
visited[i][0] = 1;
}
for (int i = 1; i <= W; i++) {
visited[0][i] = 1;
visited[W + 1][i] = 1;
}
lli ans = 0;
lli dir[] = {1, 0, -1, 0, 1};
while (!q.empty()) {
tlll t = q.front();
q.pop();
if (visited[get<0>(t)][get<1>(t)] == 0) {
visited[get<0>(t)][get<1>(t)] = get<2>(t);
ans = get<2>(t);
for (int i = 0; i < 4; i++)
q.push(tlll{get<0>(t) + dir[i], get<1>(t) + dir[i + 1], get<2>(t) + 1});
}
}
COUT(ans - 1);
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define CHMAX(a, b) a = std::max(a, b)
#define CHMIN(a, b) a = std::min(a, b)
#define CHABS(a) a = std::abs(a)
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for (lli i = 0; i < n; i++)
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
lli mod197 = 1000000007LL;
// ax + by = gcd(a,b) 最大公約数
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
lli visited[1002][1002] = {};
int main(void) {
lli H, W;
cin >> H >> W;
std::queue<tlll> q;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c;
cin >> c;
if (c == '#') {
q.push(tlll{i + 1, j + 1, 1});
}
}
}
for (int i = 1; i <= H; i++) {
visited[i][W + 1] = 1;
visited[i][0] = 1;
}
for (int i = 1; i <= W; i++) {
visited[0][i] = 1;
visited[H + 1][i] = 1;
}
lli ans = 0;
lli dir[] = {1, 0, -1, 0, 1};
while (!q.empty()) {
tlll t = q.front();
q.pop();
if (visited[get<0>(t)][get<1>(t)] == 0) {
visited[get<0>(t)][get<1>(t)] = get<2>(t);
ans = get<2>(t);
for (int i = 0; i < 4; i++)
q.push(tlll{get<0>(t) + dir[i], get<1>(t) + dir[i + 1], get<2>(t) + 1});
}
}
COUT(ans - 1);
return 0;
} | [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 868,929 | 868,930 | u155216115 | cpp |
p03053 | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
struct Square {
int x;
int y;
int dist;
Square(int _x, int _y, int _dist) : x(_x), y(_y), dist(_dist) {}
};
int main() {
int H, W;
cin >> H >> W;
queue<Square> q;
vector<vi> reached(H, vi(W, 0));
for (int i = 0; i < H; i++) {
string s;
cin >> s;
for (int j = 0; j < W; j++) {
if (s[j] == '#') { //黒
q.push(Square(j, i, 0));
reached[i][j] = 1;
}
}
}
int max = 0;
while (!q.empty()) {
Square sq = q.front();
q.pop();
int nextx, nexty;
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: //上
nexty = sq.y - 1;
nextx = sq.x;
break;
case 1: //下
nexty = sq.y + 1;
nextx = sq.x;
break;
case 2: //左
nexty = sq.y;
nextx = sq.x - 1;
break;
case 3: //右
nexty = sq.y;
nextx = sq.x + 1;
break;
}
if (nexty >= 0 && nexty < H && nextx >= 0 && nextx < W &&
reached[nexty][nextx] == 0) {
Square next(nexty, nextx, sq.dist + 1);
q.push(next);
reached[nexty][nextx] = 1;
if (max < next.dist) {
max = next.dist;
}
}
}
}
cout << max << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
struct Square {
int x;
int y;
int dist;
Square(int _x, int _y, int _dist) : x(_x), y(_y), dist(_dist) {}
};
int main() {
int H, W;
cin >> H >> W;
queue<Square> q;
vector<vi> reached(H, vi(W, 0));
for (int i = 0; i < H; i++) {
string s;
cin >> s;
for (int j = 0; j < W; j++) {
if (s[j] == '#') { //黒
q.push(Square(j, i, 0));
reached[i][j] = 1;
}
}
}
int max = 0;
while (!q.empty()) {
Square sq = q.front();
q.pop();
int nextx, nexty;
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: //上
nexty = sq.y - 1;
nextx = sq.x;
break;
case 1: //下
nexty = sq.y + 1;
nextx = sq.x;
break;
case 2: //左
nexty = sq.y;
nextx = sq.x - 1;
break;
case 3: //右
nexty = sq.y;
nextx = sq.x + 1;
break;
}
if (nexty >= 0 && nexty < H && nextx >= 0 && nextx < W &&
reached[nexty][nextx] == 0) {
Square next(nextx, nexty, sq.dist + 1);
q.push(next);
reached[nexty][nextx] = 1;
if (max < next.dist) {
max = next.dist;
}
}
}
}
cout << max << endl;
return 0;
} | [
"call.arguments.change",
"call.arguments.add"
] | 868,939 | 868,940 | u420528322 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int h, w, n;
vector<string> s;
vector<vector<int>> steps;
void bfs(vector<P> &starts) {
queue<P> q;
for (auto s : starts) {
q.push(s);
steps[s.first][s.second] = 0;
}
while (!q.empty()) {
int y, x;
tie(y, x) = q.front();
q.pop();
for (int k = 0; k < 4; k++) {
int ny = y + dy[k];
int nx = x + dx[k];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (s[ny][nx] == '#')
continue;
s[ny][nx] = '#';
steps[ny][nx] = min(steps[ny][nx], steps[y][x] + 1);
q.emplace(nx, ny);
}
}
return;
}
int main() {
#ifdef MYLOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
cin >> h >> w;
s.resize(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
steps.resize(h);
for (int i = 0; i < h; i++) {
steps[i].resize(w);
}
vector<P> starts;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
steps[i][j] = INF32;
if (s[i][j] == '#') {
starts.push_back(make_pair(i, j));
}
}
}
bfs(starts);
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
ans = max(ans, steps[i][j]);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int h, w, n;
vector<string> s;
vector<vector<int>> steps;
void bfs(vector<P> &starts) {
queue<P> q;
for (auto s : starts) {
q.push(s);
steps[s.first][s.second] = 0;
}
while (!q.empty()) {
int y, x;
tie(y, x) = q.front();
q.pop();
for (int k = 0; k < 4; k++) {
int ny = y + dy[k];
int nx = x + dx[k];
if (nx < 0 || w <= nx || ny < 0 || h <= ny)
continue;
if (s[ny][nx] == '#')
continue;
s[ny][nx] = '#';
steps[ny][nx] = min(steps[ny][nx], steps[y][x] + 1);
q.emplace(ny, nx);
}
}
return;
}
int main() {
#ifdef MYLOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
cin >> h >> w;
s.resize(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
steps.resize(h);
for (int i = 0; i < h; i++) {
steps[i].resize(w);
}
vector<P> starts;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
steps[i][j] = INF32;
if (s[i][j] == '#') {
starts.push_back(make_pair(i, j));
}
}
}
bfs(starts);
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
ans = max(ans, steps[i][j]);
}
}
cout << ans << endl;
return 0;
}
| [
"call.arguments.change",
"call.arguments.add"
] | 868,941 | 868,942 | u335667012 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
using namespace std;
typedef long long int ll;
const ll INF = (ll)1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h);
vector<vector<int>> d(h, vector<int>(w, -1));
queue<pair<int, int>> q;
REP(i, h) {
REP(j, w) {
char c;
cin >> c;
a[i].push_back(c);
if (c == '#') {
q.push(make_pair(i, j));
d[i][j] = 0;
}
}
}
int ans = 0;
while (!q.empty()) {
pair<int, int> pos = q.front();
q.pop();
REP(i, 4) {
int x = pos.first + dx[i];
int y = pos.second + dy[i];
if (x < 0 || x >= w || y < 0 || y >= h)
continue;
if (a[x][y] == '#')
continue;
a[x][y] = '#';
d[x][y] = d[pos.first][pos.second] + 1;
ans = max(ans, d[x][y]);
q.push(make_pair(x, y));
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
using namespace std;
typedef long long int ll;
const ll INF = (ll)1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h);
vector<vector<int>> d(h, vector<int>(w, -1));
queue<pair<int, int>> q;
REP(i, h) {
REP(j, w) {
char c;
cin >> c;
a[i].push_back(c);
if (c == '#') {
q.push(make_pair(i, j));
d[i][j] = 0;
}
}
}
int ans = 0;
while (!q.empty()) {
pair<int, int> pos = q.front();
q.pop();
REP(i, 4) {
int x = pos.first + dx[i];
int y = pos.second + dy[i];
if (x < 0 || x >= h || y < 0 || y >= w)
continue;
if (a[x][y] == '#')
continue;
a[x][y] = '#';
d[x][y] = d[pos.first][pos.second] + 1;
ans = max(ans, d[x][y]);
q.push(make_pair(x, y));
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 868,946 | 868,947 | u868089307 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX 1000
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
char a[h][w];
REP(i, h) REP(j, w) cin >> a[i][j];
int dist[h][w];
REP(i, h) REP(j, w) dist[i][j] = INF;
queue<P> que;
REP(i, h) {
REP(j, w) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(P(i, j));
}
}
}
while (que.size()) {
P p = que.front();
que.pop();
REP(i, 4) {
int nx = p.first + dx[i], ny = p.second + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < h && dist[nx][ny] == INF) {
que.push(P(nx, ny));
dist[nx][ny] = dist[p.first][p.second] + 1;
}
}
}
int ans = 0;
REP(i, h) REP(j, w) ans = max(ans, dist[i][j]);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX 1000
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
char a[h][w];
REP(i, h) REP(j, w) cin >> a[i][j];
int dist[h][w];
REP(i, h) REP(j, w) dist[i][j] = INF;
queue<P> que;
REP(i, h) {
REP(j, w) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(P(i, j));
}
}
}
while (que.size()) {
P p = que.front();
que.pop();
REP(i, 4) {
int nx = p.first + dx[i], ny = p.second + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < w && dist[nx][ny] == INF) {
que.push(P(nx, ny));
dist[nx][ny] = dist[p.first][p.second] + 1;
}
}
}
int ans = 0;
REP(i, h) REP(j, w) ans = max(ans, dist[i][j]);
cout << ans << endl;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 868,953 | 868,954 | u366398972 | cpp |
p03053 | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;
#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD
int main() {
int H, W;
cin >> H >> W;
char A[H][W];
REP(i, H)
REP(j, W)
cin >> A[i][j];
int dist[H][W];
REP(i, H)
REP(j, W)
dist[i][j] = -1;
queue<P> que;
REP(i, H)
REP(j, W) {
if (A[i][j] == '#') {
que.push(make_pair(i, j));
dist[i][j] = 0;
}
}
int dy[4] = {0, -1, 0, 1};
int dx[4] = {-1, 0, 1, 0};
while (que.size()) {
P p = que.front();
que.pop();
REP(i, 4) {
int ny = p.first + dy[i];
int nx = p.second + dx[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W && dist[ny][nx] == -1) {
que.push(make_pair(ny, nx));
dist[ny][nx] = dist[p.first][p.second] + 1;
}
}
}
int ans = 0;
REP(i, H)
REP(j, W) {
if (ans < dist[i][j])
ans = dist[i][j];
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;
#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD
int main() {
int H, W;
cin >> H >> W;
char A[H][W];
REP(i, H)
REP(j, W)
cin >> A[i][j];
int dist[H][W];
REP(i, H)
REP(j, W)
dist[i][j] = -1;
queue<P> que;
REP(i, H)
REP(j, W) {
if (A[i][j] == '#') {
que.push(make_pair(i, j));
dist[i][j] = 0;
}
}
int dy[4] = {0, -1, 0, 1};
int dx[4] = {-1, 0, 1, 0};
while (que.size()) {
P p = que.front();
que.pop();
REP(i, 4) {
int ny = p.first + dy[i];
int nx = p.second + dx[i];
if (0 <= ny && ny < H && 0 <= nx && nx < W && dist[ny][nx] == -1) {
que.push(make_pair(ny, nx));
dist[ny][nx] = dist[p.first][p.second] + 1;
}
}
}
int ans = 0;
REP(i, H)
REP(j, W) {
if (ans < dist[i][j])
ans = dist[i][j];
}
cout << ans << endl;
return 0;
} | [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 868,957 | 868,958 | u722397179 | cpp |
p03053 | #include <iostream>
#include <queue>
using namespace std;
const int INF = (int)1e9;
struct dat {
int x, y, d;
};
int H, W;
char grid[1000][1000];
int dist[1000][1000];
int ans;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
queue<dat> que;
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> grid[i][j];
dist[i][j] = INF;
if (grid[i][j] == '#') {
que.push({i, j, 0});
dist[i][j] = 0;
}
}
}
while (que.size()) {
dat from = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int nx = from.x + dx[i], ny = from.y + dy[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W && dist[nx][ny] != INF) {
que.push({nx, ny, from.d + 1});
dist[nx][ny] = from.d + 1;
ans = max(ans, dist[nx][ny]);
}
}
}
cout << ans << endl;
} | #include <iostream>
#include <queue>
using namespace std;
const int INF = (int)1e9;
struct dat {
int x, y, d;
};
int H, W;
char grid[1000][1000];
int dist[1000][1000];
int ans = 0;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
queue<dat> que;
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> grid[i][j];
dist[i][j] = INF;
if (grid[i][j] == '#') {
que.push({i, j, 0});
dist[i][j] = 0;
}
}
}
while (que.size()) {
dat from = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int nx = from.x + dx[i], ny = from.y + dy[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W && dist[nx][ny] == INF) {
que.push({nx, ny, from.d + 1});
dist[nx][ny] = from.d + 1;
ans = max(ans, dist[nx][ny]);
}
}
}
cout << ans << endl;
} | [
"variable_declaration.value.change",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 868,961 | 868,960 | u525137785 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
};
int h, w, k;
char a[1111][1111];
int o[1111][1111], dx[10] = {1, 0, -1, 0}, dy[10] = {0, 1, 0, -1};
queue<P> q;
int main() {
memset(o, -1, sizeof(o));
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++)
scanf("%s", a[i] + 1);
for (int i = 1; i <= h; i++)
for (int j = 1; j <= h; j++)
if (a[i][j] == '#') {
o[i][j] = 0;
q.push({i, j});
}
for (; q.size(); q.pop())
for (int h = 0; h < 4; h++) {
int x = dx[h] + q.front().x, y = dy[h] + q.front().y;
if (o[x][y] < 0 && a[x][y]) {
o[x][y] = o[q.front().x][q.front().y] + 1;
k = max(k, o[x][y]);
q.push({x, y});
}
}
printf("%d", k);
}
| #include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
};
int h, w, k;
char a[1111][1111];
int o[1111][1111], dx[10] = {1, 0, -1, 0}, dy[10] = {0, 1, 0, -1};
queue<P> q;
int main() {
memset(o, -1, sizeof(o));
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++)
scanf("%s", a[i] + 1);
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
if (a[i][j] == '#') {
o[i][j] = 0;
q.push({i, j});
}
for (; q.size(); q.pop())
for (int h = 0; h < 4; h++) {
int x = dx[h] + q.front().x, y = dy[h] + q.front().y;
if (o[x][y] < 0 && a[x][y]) {
o[x][y] = o[q.front().x][q.front().y] + 1;
k = max(k, o[x][y]);
q.push({x, y});
}
}
printf("%d", k);
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 868,962 | 868,963 | u428070871 | cpp |
p03053 | /*
こんにちは。あたしはカウガール。
redcoderになるためAtCoderを巡る旅をしてます。
__
ヽ|__|ノ モォ
||‘‐‘||レ _)_, ―‐ 、
/(Y (ヽ_ /・ ヽ  ̄ヽ
∠ _ ゝ `^ヽ ノ.::::_(ノヽ
_/ヽ /ヽ ̄ ̄/ヽ
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> a(h);
rep(i, h) cin >> a[i];
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> que;
rep(i, h) {
rep(j, h) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cur.first][cur.second] + 1;
que.push(make_pair(nx, ny));
}
}
}
int res = 0;
rep(i, h) rep(j, w) { res = max(res, dist[i][j]); }
cout << res << endl;
}
| /*
こんにちは。あたしはカウガール。
redcoderになるためAtCoderを巡る旅をしてます。
__
ヽ|__|ノ モォ
||‘‐‘||レ _)_, ―‐ 、
/(Y (ヽ_ /・ ヽ  ̄ヽ
∠ _ ゝ `^ヽ ノ.::::_(ノヽ
_/ヽ /ヽ ̄ ̄/ヽ
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> a(h);
rep(i, h) cin >> a[i];
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> que;
rep(i, h) {
rep(j, w) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cur.first][cur.second] + 1;
que.push(make_pair(nx, ny));
}
}
}
int res = 0;
rep(i, h) rep(j, w) { res = max(res, dist[i][j]); }
cout << res << endl;
}
| [] | 868,966 | 868,967 | u038027079 | cpp |
p03053 | /*
こんにちは。あたしはカウガール。
redcoderになるためAtCoderを巡る旅をしてます。
__
ヽ|__|ノ モォ
||‘‐‘||レ _)_, ―‐ 、
/(Y (ヽ_ /・ ヽ  ̄ヽ
∠ _ ゝ `^ヽ ノ.::::_(ノヽ
_/ヽ /ヽ ̄ ̄/ヽ
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> a(h);
rep(i, h) cin >> a[i];
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> que;
rep(i, h) {
rep(j, h) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cur.first][cur.second] + 1;
que.push(make_pair(nx, ny));
}
}
}
int res = 0;
rep(i, h) rep(j, w) { res = max(res, dist[i][j]); }
cout << res << endl;
}
| /*
こんにちは。あたしはカウガール。
redcoderになるためAtCoderを巡る旅をしてます。
__
ヽ|__|ノ モォ
||‘‐‘||レ _)_, ―‐ 、
/(Y (ヽ_ /・ ヽ  ̄ヽ
∠ _ ゝ `^ヽ ノ.::::_(ノヽ
_/ヽ /ヽ ̄ ̄/ヽ
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> a(h);
rep(i, h) cin >> a[i];
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> que;
rep(i, h) {
rep(j, w) {
if (a[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= h || ny < 0 || ny >= w)
continue;
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cur.first][cur.second] + 1;
que.push(make_pair(nx, ny));
}
}
}
int res = 0;
rep(i, h) rep(j, w) { res = max(res, dist[i][j]); }
cout << res << endl;
}
| [
"expression.operation.unary.arithmetic.remove",
"expression.operation.unary.arithmetic.add"
] | 868,968 | 868,967 | u038027079 | cpp |
p03053 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll, ll> MPll;
typedef set<ll> setl;
const ll INF = 1ll << 60;
const ld EPS = 1e-10;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// for文
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define FORE(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define REP(i, size) for (ll i = (ll)0; i < size; i++)
#define REPE(i, size) for (ll i = (ll)0; i <= size; i++)
#define REPR(i, size) for (ll i = (ll)size; i >= 0; i--)
#define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++)
//ソート
#define ALL(vec) (vec).begin(), (vec).end()
#define SORT(vec) sort(ALL(vec))
#define SORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll)))
#define INVSORT(vec) sort((vec).rbegin(), (vec).rend())
#define REV(vec) reverse(ALL(vec))
#define REVA(arr) reverse(arr, arr + (sizeof(arr) / sizeof(ll)))
#define INVSORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))), REVA(arr)
//最大値最小値
#define MAX(vec) *max_element(ALL(vec))
#define UNIQ(vec) \
SORT(vec); \
vec.erase(unique(ALL(vec)), vec.end())
#define MIN(vec) *min_element(ALL(vec))
//出力
#define printl(a) cout << a << "\n"
#define print(a) cout << a
#define OUT(a) printf("%lld\n", a)
#define OUTA(array) \
REP(i, sizeof(array) / sizeof(ll)) printf("%lld\n", array[i])
#define OUTV(vec) REP(i, vec.size()) printf("%lld\n", vec[i])
#define SP printf(" ")
//入力
#define IN(x) scanf("%lld", &x)
#define INV(vec) REP(i, vec.size()) scanf("%lld", &vec[i])
#define INA(array) REP(i, sizeof(array) / sizeof(ll)) scanf("%lld", array + i)
#define INS(x) cin >> x
#define INCH(x) scanf(" %c", &x)
//型
#define P pair
#define vp vector<P>
#define F first
#define S second
//その他
#define PB push_back
#define MP make_pair
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))
#define INFI(a) memset(a, INF, sizeof(a))
#define MEM(a, b) memset(a, (b), sizeof(a))
//関数
template <class T> inline void amax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> inline void amin(T &a, const T &b) {
if (a > b)
a = b;
}
/*
struct structure{
ll num1,num2,string s;
bool operator<(const rest &another) const{
return this->s < another.s;
}
structure(ll a,ll b,string s){
this->num1 = a,this->num2=b,this->s=s;
}
};a
*/
//特殊
//#define int ll
#define _CRT_SECURE_NO_WARNINGS
#define DEBUG
#ifdef DEBUG
#define debugl(x) cerr << #x << ":" << x << "\n"
#define debug(x) cerr << x
#define debugV(V) \
REP(i, V.size()) { cerr << i << ":" << V[i] << endl; }
#define debugA(A) \
REP(i, sizeof(A) / sizeof(ll)) { cerr << i << ":" << V[i] << endl; }
#else
#define debug(x)
#define debugV(x)
#define debugA(x)
#endif
signed main() {
ll H, W;
IN(H);
IN(W);
char a;
vec2 dis(W, vec(H, -1));
ll ans = 0;
queue<P<int, int>> pos;
FOR(i, 0, H) {
FOR(j, 0, W) {
INCH(a);
if (a == '#') {
pos.push(MP(i, j));
dis[i][j] = 0;
}
}
}
pair<int, int> look;
int look_x;
int look_y;
int next_x;
int next_y;
while (!pos.empty()) {
look = pos.front();
pos.pop();
look_x = look.F;
look_y = look.S;
amax(ans, dis[look_x][look_y]);
FOR(i, 0, 4) {
next_x = look_x + dx[i];
next_y = look_y + dy[i];
if (next_x < 0 or next_x >= W or next_y < 0 or next_y >= H)
continue;
if (dis[next_x][next_y] == -1) {
dis[next_x][next_y] = dis[look_x][look_y] + 1;
pos.push(MP(next_x, next_y));
}
}
}
OUT(ans);
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll, ll> MPll;
typedef set<ll> setl;
const ll INF = 1ll << 60;
const ld EPS = 1e-10;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// for文
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define FORE(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define REP(i, size) for (ll i = (ll)0; i < size; i++)
#define REPE(i, size) for (ll i = (ll)0; i <= size; i++)
#define REPR(i, size) for (ll i = (ll)size; i >= 0; i--)
#define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++)
//ソート
#define ALL(vec) (vec).begin(), (vec).end()
#define SORT(vec) sort(ALL(vec))
#define SORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll)))
#define INVSORT(vec) sort((vec).rbegin(), (vec).rend())
#define REV(vec) reverse(ALL(vec))
#define REVA(arr) reverse(arr, arr + (sizeof(arr) / sizeof(ll)))
#define INVSORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))), REVA(arr)
//最大値最小値
#define MAX(vec) *max_element(ALL(vec))
#define UNIQ(vec) \
SORT(vec); \
vec.erase(unique(ALL(vec)), vec.end())
#define MIN(vec) *min_element(ALL(vec))
//出力
#define printl(a) cout << a << "\n"
#define print(a) cout << a
#define OUT(a) printf("%lld\n", a)
#define OUTA(array) \
REP(i, sizeof(array) / sizeof(ll)) printf("%lld\n", array[i])
#define OUTV(vec) REP(i, vec.size()) printf("%lld\n", vec[i])
#define SP printf(" ")
//入力
#define IN(x) scanf("%lld", &x)
#define INV(vec) REP(i, vec.size()) scanf("%lld", &vec[i])
#define INA(array) REP(i, sizeof(array) / sizeof(ll)) scanf("%lld", array + i)
#define INS(x) cin >> x
#define INCH(x) scanf(" %c", &x)
//型
#define P pair
#define vp vector<P>
#define F first
#define S second
//その他
#define PB push_back
#define MP make_pair
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))
#define INFI(a) memset(a, INF, sizeof(a))
#define MEM(a, b) memset(a, (b), sizeof(a))
//関数
template <class T> inline void amax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> inline void amin(T &a, const T &b) {
if (a > b)
a = b;
}
/*
struct structure{
ll num1,num2,string s;
bool operator<(const rest &another) const{
return this->s < another.s;
}
structure(ll a,ll b,string s){
this->num1 = a,this->num2=b,this->s=s;
}
};a
*/
//特殊
//#define int ll
#define _CRT_SECURE_NO_WARNINGS
#define DEBUG
#ifdef DEBUG
#define debugl(x) cerr << #x << ":" << x << "\n"
#define debug(x) cerr << x
#define debugV(V) \
REP(i, V.size()) { cerr << i << ":" << V[i] << endl; }
#define debugA(A) \
REP(i, sizeof(A) / sizeof(ll)) { cerr << i << ":" << V[i] << endl; }
#else
#define debug(x)
#define debugV(x)
#define debugA(x)
#endif
signed main() {
ll H, W;
IN(H);
IN(W);
char a;
vec2 dis(W, vec(H, -1));
ll ans = 0;
queue<P<int, int>> pos;
FOR(i, 0, H) {
FOR(j, 0, W) {
INCH(a);
if (a == '#') {
pos.push(MP(j, i));
dis[j][i] = 0;
}
}
}
pair<int, int> look;
int look_x;
int look_y;
int next_x;
int next_y;
while (!pos.empty()) {
look = pos.front();
pos.pop();
look_x = look.F;
look_y = look.S;
amax(ans, dis[look_x][look_y]);
FOR(i, 0, 4) {
next_x = look_x + dx[i];
next_y = look_y + dy[i];
if (next_x < 0 or next_x >= W or next_y < 0 or next_y >= H)
continue;
if (dis[next_x][next_y] == -1) {
dis[next_x][next_y] = dis[look_x][look_y] + 1;
pos.push(MP(next_x, next_y));
}
}
}
OUT(ans);
}
| [
"call.arguments.change",
"call.arguments.add",
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 868,995 | 868,996 | u502721867 | cpp |
p03053 | #include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
queue<pair<int, int>> queue;
vector<vector<int>> dmap;
for (int i = 0; i < h; i++) {
char c;
dmap.emplace(dmap.end(), w, -1);
for (int j = 0; j < w; j++) {
cin >> c;
if (c == '#') {
queue.push(make_pair(i, j));
dmap[i][j] = 0;
}
}
cin >> c; // endl
}
int ans = -1;
while (!queue.empty()) {
int i, j;
tie(i, j) = queue.front();
queue.pop();
ans = dmap[i][j];
for (int di = -1; di <= 1; di++) {
for (int dj = -1; dj <= 1; dj++) {
if (di * dj != 0)
continue;
int ii = i + di;
int jj = j + dj;
if (ii >= 0 && ii < h && jj >= 0 && jj < w && dmap[ii][jj] == -1) {
dmap[ii][jj] = dmap[i][j] + 1;
queue.push(make_pair(ii, jj));
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
queue<pair<int, int>> queue;
vector<vector<int>> dmap;
for (int i = 0; i < h; i++) {
char c;
dmap.emplace(dmap.end(), w, -1);
for (int j = 0; j < w; j++) {
cin >> c;
if (c == '#') {
queue.push(make_pair(i, j));
dmap[i][j] = 0;
}
}
}
int ans = -1;
while (!queue.empty()) {
int i, j;
tie(i, j) = queue.front();
queue.pop();
ans = dmap[i][j];
for (int di = -1; di <= 1; di++) {
for (int dj = -1; dj <= 1; dj++) {
if (di * dj != 0)
continue;
int ii = i + di;
int jj = j + dj;
if (ii >= 0 && ii < h && jj >= 0 && jj < w && dmap[ii][jj] == -1) {
dmap[ii][jj] = dmap[i][j] + 1;
queue.push(make_pair(ii, jj));
}
}
}
}
cout << ans << endl;
return 0;
}
| [] | 869,000 | 869,001 | u321226359 | cpp |
p03053 | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
typedef long long ll;
typedef pair<int, int> pii;
class Vec2 {
public:
int x;
int y;
Vec2(int x = 0, int y = 0) : x(x), y(y){};
Vec2 operator+(Vec2 v) { return Vec2(x + v.x, y + v.y); }
Vec2 operator-(Vec2 v) { return Vec2(x - v.x, y - v.y); }
};
int main(void) {
int h, w;
cin >> h >> w;
vector<string> s;
vector<vector<int>> cost(h, vector<int>(w, 0));
queue<Vec2> q;
REP(i, h) {
cin >> s[i];
REP(j, w) {
if (s[i][j] == '#')
q.push(Vec2(i, j));
}
}
Vec2 diff[4] = {Vec2(-1, 0), Vec2(1, 0), Vec2(0, -1), Vec2(0, 1)};
int ans = 0;
while (q.size()) {
Vec2 f = q.front();
q.pop();
REP(i, 4) {
Vec2 a = f + diff[i];
if (0 <= a.x && a.x < h && 0 <= a.y && a.y <= w) {
if (s[a.x][a.y] == '.') {
q.push(a);
s[a.x][a.y] = '#';
cost[a.x][a.y] = cost[f.x][f.y] + 1;
ans = max(ans, cost[a.x][a.y]);
}
}
}
}
pr(ans);
} | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
typedef long long ll;
typedef pair<int, int> pii;
class Vec2 {
public:
int x;
int y;
Vec2(int x = 0, int y = 0) : x(x), y(y){};
Vec2 operator+(Vec2 v) { return Vec2(x + v.x, y + v.y); }
Vec2 operator-(Vec2 v) { return Vec2(x - v.x, y - v.y); }
};
int main(void) {
int h, w;
cin >> h >> w;
vector<string> s(h);
vector<vector<int>> cost(h, vector<int>(w, 0));
queue<Vec2> q;
REP(i, h) {
cin >> s[i];
REP(j, w) {
if (s[i][j] == '#')
q.push(Vec2(i, j));
}
}
Vec2 diff[4] = {Vec2(-1, 0), Vec2(1, 0), Vec2(0, -1), Vec2(0, 1)};
int ans = 0;
while (q.size()) {
Vec2 f = q.front();
q.pop();
REP(i, 4) {
Vec2 a = f + diff[i];
if (0 <= a.x && a.x < h && 0 <= a.y && a.y < w) {
if (s[a.x][a.y] == '.') {
q.push(a);
s[a.x][a.y] = '#';
cost[a.x][a.y] = cost[f.x][f.y] + 1;
ans = max(ans, cost[a.x][a.y]);
}
}
}
}
pr(ans);
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,002 | 869,003 | u528720841 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
const int dirx[4] = {1, 0, -1, 0};
const int diry[4] = {0, 1, 0, -1};
char s[1005][1005];
int used[1005][1005];
queue<tuple<int, int, int>> q;
int h, w;
bool check(int x, int y) { return x >= 1 && x <= h && y >= 1 && y <= h; }
int main() {
int ans, x, y, d, x0, y0;
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++)
scanf("%s", s[i] + 1);
ans = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (s[i][j] == '#') {
q.push(make_tuple(i, j, 0));
used[i][j] = 1;
}
}
}
while (!q.empty()) {
tie(x, y, d) = q.front();
q.pop();
ans = max(ans, d);
for (int i = 0; i < 4; i++) {
x0 = x + dirx[i];
y0 = y + diry[i];
if (check(x0, y0) && !used[x0][y0]) {
q.push(make_tuple(x0, y0, d + 1));
used[x0][y0] = 1;
}
}
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int dirx[4] = {1, 0, -1, 0};
const int diry[4] = {0, 1, 0, -1};
char s[1005][1005];
int used[1005][1005];
queue<tuple<int, int, int>> q;
int h, w;
bool check(int x, int y) { return x >= 1 && x <= h && y >= 1 && y <= w; }
int main() {
int ans, x, y, d, x0, y0;
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++)
scanf("%s", s[i] + 1);
ans = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (s[i][j] == '#') {
q.push(make_tuple(i, j, 0));
used[i][j] = 1;
}
}
}
while (!q.empty()) {
tie(x, y, d) = q.front();
q.pop();
ans = max(ans, d);
for (int i = 0; i < 4; i++) {
x0 = x + dirx[i];
y0 = y + diry[i];
if (check(x0, y0) && !used[x0][y0]) {
q.push(make_tuple(x0, y0, d + 1));
used[x0][y0] = 1;
}
}
}
printf("%d\n", ans);
return 0;
} | [
"identifier.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 869,009 | 869,010 | u593031180 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[1005];
struct node {
int x, y;
int step;
node(int x, int y, int step) : x(x), y(y), step(step) {}
};
queue<node> q;
int vis[1005][1005];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (s[i][j] == '#') {
q.push(node(i, j, 0));
vis[i][j] = 1;
}
}
}
int ans = 0;
while (!q.empty()) {
node now = q.front();
q.pop();
for (int i = 0; i < 4; ++i) {
int xx = now.x + dir[i][0];
int yy = now.y + dir[i][1];
if (xx >= 0 && xx < n && yy >= 0 && yy < m && !vis[xx][yy]) {
q.push(node(xx, yy, now.step + 1));
ans = max(ans, now.step + 1);
vis[xx][yy] = 1;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[1005];
struct node {
int x, y;
int step;
node(int x, int y, int step) : x(x), y(y), step(step) {}
};
queue<node> q;
int vis[1005][1005];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (s[i][j] == '#') {
q.push(node(i, j, 0));
vis[i][j] = 1;
}
}
}
int ans = 0;
while (!q.empty()) {
node now = q.front();
q.pop();
for (int i = 0; i < 4; ++i) {
int xx = now.x + dir[i][0];
int yy = now.y + dir[i][1];
if (xx >= 0 && xx < n && yy >= 0 && yy < m && !vis[xx][yy]) {
q.push(node(xx, yy, now.step + 1));
ans = max(ans, now.step + 1);
vis[xx][yy] = 1;
}
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 869,024 | 869,025 | u976418120 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
ll inf = 1e15;
vll dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w;
cin >> h >> w;
vvll a(h, vll(w, inf)), visited(h, vll(w, 0));
;
queue<P> que;
char c;
REP(i, h) {
REP(j, w) {
cin >> c;
if (c == '#') {
a[i][j] = 0;
que.push(P{j, i});
visited[i][j] = 1;
}
}
}
while (!que.empty()) {
ll cx = que.front().first, cy = que.front().second;
que.pop();
REP(i, 4) {
ll nx = cx + dx[i], ny = cy + dy[i];
if ((nx >= 0 && nx < w && ny >= 0 && ny < h) && !visited[ny][nx]) {
a[ny][nx] = a[cy][cx] + 1;
visited[ny][nx] = 1;
que.push(P{ny, nx});
}
}
}
ll res = 0;
REP(i, h) {
REP(j, w) { res = max(res, a[i][j]); }
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
ll inf = 1e15;
vll dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w;
cin >> h >> w;
vvll a(h, vll(w, inf)), visited(h, vll(w, 0));
;
queue<P> que;
char c;
REP(i, h) {
REP(j, w) {
cin >> c;
if (c == '#') {
a[i][j] = 0;
que.push(P{i, j});
visited[i][j] = 1;
}
}
}
while (!que.empty()) {
ll cx = que.front().second, cy = que.front().first;
que.pop();
REP(i, 4) {
ll nx = cx + dx[i], ny = cy + dy[i];
if ((nx >= 0 && nx < w && ny >= 0 && ny < h) && !visited[ny][nx]) {
a[ny][nx] = a[cy][cx] + 1;
visited[ny][nx] = 1;
que.push(P{ny, nx});
}
}
}
ll res = 0;
REP(i, h) {
REP(j, w) { res = max(res, a[i][j]); }
}
cout << res << endl;
return 0;
} | [] | 869,028 | 869,029 | u986276444 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e6;
const int X[4] = {0, 1, 0, -1}, Y[4] = {1, 0, -1, 0};
int n, m, l, r;
int q[N], v[N];
#define C getchar()
void in() {
cin >> n >> m;
C;
for (int i = 0; ++i <= n; C)
for (int j = 0; ++j <= m;)
if (C == '#')
v[q[++r] = i * m + j] = 1;
}
int d[N];
void wor() {
while (++l <= r) {
int x = (q[l] - 1) / m, y = (q[l] - 1) % m + 1;
for (int i = 4; ~--i;)
if (x + X[i] && x + X[i] < n && y + Y[i] && y + Y[i] < m) {
int p = (x + X[i]) * m + (y + Y[i]);
if (!v[p])
v[p] = 1, q[++r] = p, d[p] = d[q[l]] + 1;
}
}
}
void out() { cout << d[q[r]]; }
int main() {
in();
wor();
out();
exit(0);
} | #include <bits/stdc++.h>
using namespace std;
const int N = 5e6;
const int X[4] = {0, 1, 0, -1}, Y[4] = {1, 0, -1, 0};
int n, m, l, r;
int q[N], v[N];
#define C getchar()
void in() {
cin >> n >> m;
C;
for (int i = 0; ++i <= n; C)
for (int j = 0; ++j <= m;)
if (C == '#')
v[q[++r] = i * m + j] = 1;
}
int d[N];
void wor() {
while (++l <= r) {
int x = (q[l] - 1) / m, y = (q[l] - 1) % m + 1;
for (int i = 4; ~--i;)
if (x + X[i] && x + X[i] <= n && y + Y[i] && y + Y[i] <= m) {
int p = (x + X[i]) * m + (y + Y[i]);
if (!v[p])
v[p] = 1, q[++r] = p, d[p] = d[q[l]] + 1;
}
}
}
void out() { cout << d[q[r]]; }
int main() {
in();
wor();
out();
exit(0);
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,030 | 869,031 | u350552300 | cpp |
p03053 | #include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define all(v) begin(v), end(v)
#define debug(x) // std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x, y) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3( \
x, y, \
z) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
using ll = long long;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
template <typename T> using vvec = std::vector<std::vector<T>>;
template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); }
template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...));
}
template <typename T> void fill_v(T &var, const T &x) { var = x; }
template <typename V, typename T> void fill_v(V &v, const T &x) {
for (auto &&w : v) {
fill_v(w, x);
}
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
int sz = v.size();
s << "\n";
rep(i, sz) {
s << v[i];
if (i < sz - 1) {
s << "\t";
}
}
s << "\n";
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s,
const std::vector<std::vector<T>> &v) {
for (auto &&w : v) {
s << w;
}
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) {
int sz = v.size();
s << "\n";
rep(i, sz) {
s << v[i];
if (i < sz - 1) {
s << "\t";
}
}
s << "\n";
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) {
for (auto &&w : v) {
s << w;
}
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::set<T> &v) {
s << "\n";
for (auto &&elm : v) {
s << elm << "\t";
}
s << "\n";
return s;
}
inline void scan(int &a) { scanf("%d", &a); }
inline void scan(ll &a) { scanf("%lld", &a); }
inline void scan(char &a) { scanf(" %c", &a); }
inline void scan(double &a) { scanf("%lf", &a); }
inline void scan(std::string &s) {
char BUF[3000000];
scanf(" %s", BUF);
s = std::string(BUF);
}
template <typename T> inline void scan(std::vector<T> &v) {
for (auto &&sv : v) {
scan(sv);
}
}
template <typename First, typename... Args>
inline void scan(First &f, Args &...args) {
scan(f);
scan(args...);
}
inline void print(int a) { printf("%d\n", a); }
inline void print(ll a) { printf("%lld\n", a); }
inline void print(double a) { printf("%.12f\n", a); }
inline void print(std::string s) { std::cout << s << "\n"; }
using namespace std;
int main() {
int h, w;
scan(h, w);
int NOT_TOUCH = 99999;
vvi dist(h, vi(w, NOT_TOUCH));
deque<int> que;
rep(i, h) {
rep(j, w) {
char c;
scan(c);
if (c == '#') {
dist[i][j] = 0;
que.push_back(i * h + j);
}
}
}
debug(dist);
vi dh = {0, 1, 0, -1};
vi dw = {1, 0, -1, 0};
while (!que.empty()) {
int t = que.front();
que.pop_front();
int i = t / h;
int j = t - i * h;
debug2(i, j);
rep(k, 4) {
int nh = i + dh[k];
int nw = j + dw[k];
debug2(nh, nw);
if (nh < 0 || h <= nh || nw < 0 || w <= nw) {
continue;
}
if (dist[nh][nw] == NOT_TOUCH) {
dist[nh][nw] = dist[i][j] + 1;
que.push_back(nh * h + nw);
} else {
assert(dist[nh][nw] <= dist[i][j] + 1);
}
}
debug(dist);
}
int ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, dist[i][j]); }
}
print(ans);
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define all(v) begin(v), end(v)
#define debug(x) // std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x, y) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3( \
x, y, \
z) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
using ll = long long;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
template <typename T> using vvec = std::vector<std::vector<T>>;
template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); }
template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...));
}
template <typename T> void fill_v(T &var, const T &x) { var = x; }
template <typename V, typename T> void fill_v(V &v, const T &x) {
for (auto &&w : v) {
fill_v(w, x);
}
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
int sz = v.size();
s << "\n";
rep(i, sz) {
s << v[i];
if (i < sz - 1) {
s << "\t";
}
}
s << "\n";
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s,
const std::vector<std::vector<T>> &v) {
for (auto &&w : v) {
s << w;
}
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) {
int sz = v.size();
s << "\n";
rep(i, sz) {
s << v[i];
if (i < sz - 1) {
s << "\t";
}
}
s << "\n";
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) {
for (auto &&w : v) {
s << w;
}
return s;
}
template <typename T>
std::ostream &operator<<(std::ostream &s, const std::set<T> &v) {
s << "\n";
for (auto &&elm : v) {
s << elm << "\t";
}
s << "\n";
return s;
}
inline void scan(int &a) { scanf("%d", &a); }
inline void scan(ll &a) { scanf("%lld", &a); }
inline void scan(char &a) { scanf(" %c", &a); }
inline void scan(double &a) { scanf("%lf", &a); }
inline void scan(std::string &s) {
char BUF[3000000];
scanf(" %s", BUF);
s = std::string(BUF);
}
template <typename T> inline void scan(std::vector<T> &v) {
for (auto &&sv : v) {
scan(sv);
}
}
template <typename First, typename... Args>
inline void scan(First &f, Args &...args) {
scan(f);
scan(args...);
}
inline void print(int a) { printf("%d\n", a); }
inline void print(ll a) { printf("%lld\n", a); }
inline void print(double a) { printf("%.12f\n", a); }
inline void print(std::string s) { std::cout << s << "\n"; }
using namespace std;
int main() {
int h, w;
scan(h, w);
int NOT_TOUCH = 99999;
vvi dist(h, vi(w, NOT_TOUCH));
deque<int> que;
rep(i, h) {
rep(j, w) {
char c;
scan(c);
if (c == '#') {
dist[i][j] = 0;
que.push_back(i * w + j);
}
}
}
debug(dist);
vi dh = {0, 1, 0, -1};
vi dw = {1, 0, -1, 0};
while (!que.empty()) {
int t = que.front();
que.pop_front();
int i = t / w;
int j = t - i * w;
debug2(i, j);
rep(k, 4) {
int nh = i + dh[k];
int nw = j + dw[k];
debug2(nh, nw);
if (nh < 0 || h <= nh || nw < 0 || w <= nw) {
continue;
}
if (dist[nh][nw] == NOT_TOUCH) {
dist[nh][nw] = dist[i][j] + 1;
que.push_back(nh * w + nw);
} else {
assert(dist[nh][nw] <= dist[i][j] + 1);
}
}
debug(dist);
}
int ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, dist[i][j]); }
}
print(ans);
return 0;
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,045 | 869,046 | u500496457 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '.';
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct node {
int x, y, step;
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", a[i]);
queue<node> que;
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '#')
que.push({i, j, 0});
while (!que.empty()) {
int x = que.front().x, y = que.front().y, st = que.front().step;
que.pop();
cnt = max(cnt, st);
for (int i = 0; i < 4; i++) {
int fx = x + dx[i], fy = y + dy[i];
if (check(fx, fy))
que.push({fx, fy, st + 1});
a[fx][fy] = '#';
}
}
printf("%d\n", cnt);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '.';
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct node {
int x, y, step;
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", a[i]);
queue<node> que;
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '#')
que.push({i, j, 0});
while (!que.empty()) {
int x = que.front().x, y = que.front().y, st = que.front().step;
que.pop();
cnt = max(cnt, st);
for (int i = 0; i < 4; i++) {
int fx = x + dx[i], fy = y + dy[i];
if (check(fx, fy)) {
que.push({fx, fy, st + 1});
a[fx][fy] = '#';
}
}
}
printf("%d\n", cnt);
return 0;
}
| [] | 869,049 | 869,050 | u699602362 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '.';
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct node {
int x, y, step;
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", a[i]);
queue<node> que;
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '#')
que.push({i, j, 0});
while (!que.empty()) {
int x = que.front().x, y = que.front().y, st = que.front().step;
que.pop();
cnt = max(cnt, st);
for (int i = 0; i < 4; i++) {
int fx = x + dx[i], fy = y + dy[i];
if (check(fx, fy))
que.push({fx, fy, st + 1});
a[x][y] = '#';
}
}
printf("%d\n", cnt);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '.';
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct node {
int x, y, step;
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", a[i]);
queue<node> que;
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '#')
que.push({i, j, 0});
while (!que.empty()) {
int x = que.front().x, y = que.front().y, st = que.front().step;
que.pop();
cnt = max(cnt, st);
for (int i = 0; i < 4; i++) {
int fx = x + dx[i], fy = y + dy[i];
if (check(fx, fy)) {
que.push({fx, fy, st + 1});
a[fx][fy] = '#';
}
}
}
printf("%d\n", cnt);
return 0;
}
| [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 869,051 | 869,050 | u699602362 | cpp |
p03053 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// a
int h, w;
cin >> h >> w;
static char in[1400][1400] = {};
static int dist[1400][1400];
memset(dist, -1, sizeof(dist));
queue<pair<int, int>> que;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> in[i][j];
if (in[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (que.size()) {
auto cur = que.front();
que.pop();
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
for (int i = 0; i < 4; i++) {
int x = cur.first + dx[i];
int y = cur.second + dy[i];
if (x < 0 || x >= w || y < 0 || y >= h || dist[x][y] != -1 ||
in[x][y] == '#')
continue;
dist[x][y] = dist[cur.first][cur.second] + 1;
que.push(make_pair(x, y));
}
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// a
int h, w;
cin >> h >> w;
static char in[1400][1400] = {};
static int dist[1400][1400];
memset(dist, -1, sizeof(dist));
queue<pair<int, int>> que;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> in[i][j];
if (in[i][j] == '#') {
dist[i][j] = 0;
que.push(make_pair(i, j));
}
}
}
while (que.size()) {
auto cur = que.front();
que.pop();
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
for (int i = 0; i < 4; i++) {
int x = cur.first + dx[i];
int y = cur.second + dy[i];
if (x < 0 || x >= h || y < 0 || y >= w || dist[x][y] != -1 ||
in[x][y] == '#')
continue;
dist[x][y] = dist[cur.first][cur.second] + 1;
que.push(make_pair(x, y));
}
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
// cerr << dist[i][j];
ans = max(ans, dist[i][j]);
}
// cerr << endl;
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,058 | 869,059 | u817760251 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double
lin h, w;
bool a[1001][1001];
int main(void) {
vector<pair<lin, lin>> q;
cin >> h >> w;
rep(i, h) {
string s;
cin >> s;
rep(j, w) {
a[j][i] = s[j] == '#';
if (a[j][i])
q.push_back(make_pair(j, i));
}
}
lin b = q.size();
lin res = 0;
vector<pair<lin, lin>> d;
d.push_back(make_pair(1, 0));
d.push_back(make_pair(-1, 0));
d.push_back(make_pair(0, 1));
d.push_back(make_pair(0, -1));
while (b < h * w) {
vector<pair<lin, lin>> qq;
rep(i, q.size()) {
auto p = q[i];
rep(j, d.size()) {
lin x = p.first + d[j].first;
lin y = p.second + d[j].second;
if (x < 0 || w <= x || y < 0 || h <= y)
continue;
if (a[y][x])
continue;
a[y][x] = true;
qq.push_back(make_pair(x, y));
}
}
b += qq.size();
q = qq;
res++;
// cout << b << "," << res << endl;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double
lin h, w;
bool a[1001][1001];
int main(void) {
vector<pair<lin, lin>> q;
cin >> h >> w;
rep(i, h) {
string s;
cin >> s;
rep(j, w) {
a[j][i] = s[j] == '#';
if (a[j][i])
q.push_back(make_pair(j, i));
}
}
lin b = q.size();
lin res = 0;
vector<pair<lin, lin>> d;
d.push_back(make_pair(1, 0));
d.push_back(make_pair(-1, 0));
d.push_back(make_pair(0, 1));
d.push_back(make_pair(0, -1));
while (b < h * w) {
vector<pair<lin, lin>> qq;
rep(i, q.size()) {
auto p = q[i];
rep(j, d.size()) {
lin x = p.first + d[j].first;
lin y = p.second + d[j].second;
if (x < 0 || w <= x || y < 0 || h <= y)
continue;
if (a[x][y])
continue;
a[x][y] = true;
qq.push_back(make_pair(x, y));
}
}
b += qq.size();
q = qq;
res++;
// cout << b << "," << res << endl;
}
cout << res << endl;
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.variable.change"
] | 869,060 | 869,061 | u762193256 | cpp |
p03053 | #include <iostream>
#include <queue>
using namespace std;
const int INF = 100000;
typedef pair<int, int> P;
int main() {
int H, W;
char A[1000][1000];
int dist[1000][1000];
cin >> H >> W;
queue<P> que;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A[i][j];
if (A[i][j] == '#') {
dist[i][j] = 0;
que.push(P(i, j));
} else
dist[i][j] = INF;
}
}
while (!que.empty()) {
P top = que.front();
que.pop();
int i = top.first;
int j = top.second;
if (i - 1 >= 0 && dist[i - 1][j] == INF) {
dist[i - 1][j] = dist[i][j] + 1;
que.push(P(i - 1, j));
}
if (i + 1 <= H - 1 && dist[i + 1][j] == INF) {
dist[i + 1][j] = dist[i][j] + 1;
que.push(P(i + 11, j));
}
if (j - 1 >= 0 && dist[i][j - 1] == INF) {
dist[i][j - 1] = dist[i][j] + 1;
que.push(P(i, j - 1));
}
if (j + 1 <= W - 1 && dist[i][j + 1] == INF) {
dist[i][j + 1] = dist[i][j] + 1;
que.push(P(i, j + 1));
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
} | #include <iostream>
#include <queue>
using namespace std;
const int INF = 100000;
typedef pair<int, int> P;
int main() {
int H, W;
char A[1000][1000];
int dist[1000][1000];
cin >> H >> W;
queue<P> que;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> A[i][j];
if (A[i][j] == '#') {
dist[i][j] = 0;
que.push(P(i, j));
} else
dist[i][j] = INF;
}
}
while (!que.empty()) {
P top = que.front();
que.pop();
int i = top.first;
int j = top.second;
if (i - 1 >= 0 && dist[i - 1][j] == INF) {
dist[i - 1][j] = dist[i][j] + 1;
que.push(P(i - 1, j));
}
if (i + 1 <= H - 1 && dist[i + 1][j] == INF) {
dist[i + 1][j] = dist[i][j] + 1;
que.push(P(i + 1, j));
}
if (j - 1 >= 0 && dist[i][j - 1] == INF) {
dist[i][j - 1] = dist[i][j] + 1;
que.push(P(i, j - 1));
}
if (j + 1 <= W - 1 && dist[i][j + 1] == INF) {
dist[i][j + 1] = dist[i][j] + 1;
que.push(P(i, j + 1));
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,062 | 869,063 | u693133807 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int c, r;
cin >> r >> c;
vector<string> g(r);
queue<tuple<int, int, int>> q;
for (int i = 0; i < r; ++i) {
cin >> g[i];
for (int j = 0; j < c; ++j) {
if (g[i][j] == '#') {
q.push(make_tuple(i, j, 0));
}
}
}
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, 1, 0, -1};
int maxD = 0;
while (!q.empty()) {
auto cur = q.front();
q.pop();
int y = get<0>(cur), x = get<1>(cur), d = get<2>(cur);
maxD = max(maxD, d);
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= 0 && nx < c) {
if (ny >= 0 && ny < r) {
if (g[ny][nx] != '#') {
q.push(make_tuple(ny, nx, d + 1));
g[y][x] = '#';
}
}
}
}
}
cout << maxD << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int c, r;
cin >> r >> c;
vector<string> g(r);
queue<tuple<int, int, int>> q;
for (int i = 0; i < r; ++i) {
cin >> g[i];
for (int j = 0; j < c; ++j) {
if (g[i][j] == '#') {
q.push(make_tuple(i, j, 0));
}
}
}
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, 1, 0, -1};
int maxD = 0;
while (!q.empty()) {
auto cur = q.front();
q.pop();
int y = get<0>(cur), x = get<1>(cur), d = get<2>(cur);
maxD = max(maxD, d);
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= 0 && nx < c) {
if (ny >= 0 && ny < r) {
if (g[ny][nx] != '#') {
q.push(make_tuple(ny, nx, d + 1));
g[ny][nx] = '#';
}
}
}
}
}
cout << maxD << endl;
return 0;
}
| [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 869,069 | 869,070 | u499656581 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define y1 adfasfafa
const int maxn = 1e3 + 7;
typedef long long ll;
int n, m;
int ar[maxn];
char ch[maxn][maxn];
int vis[maxn][maxn];
queue<pair<int, int>> qu;
int desll[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
scanf("%d%d", &n, &m);
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] == '#') {
qu.push(make_pair(i, j));
vis[i][j] = 1;
}
}
}
int mx = 0;
while (qu.size()) {
int i = qu.front().first, j = qu.front().second;
qu.pop();
mx = max(mx, vis[i][j]);
for (int in = 0; in < 4; in++) {
int nx = desll[in][0] + i;
int ny = desll[in][1] + j;
if (nx > 0 && nx < n && ny > 0 && ny < m && !vis[nx][ny]) {
vis[nx][ny] = vis[i][j] + 1;
qu.push(make_pair(nx, ny));
}
}
}
printf("%d\n", mx - 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define y1 adfasfafa
const int maxn = 1e3 + 7;
typedef long long ll;
int n, m;
int ar[maxn];
char ch[maxn][maxn];
int vis[maxn][maxn];
queue<pair<int, int>> qu;
int desll[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
scanf("%d%d", &n, &m);
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] == '#') {
qu.push(make_pair(i, j));
vis[i][j] = 1;
}
}
}
int mx = 1;
while (qu.size()) {
int i = qu.front().first, j = qu.front().second;
qu.pop();
mx = max(mx, vis[i][j]);
for (int in = 0; in < 4; in++) {
int nx = desll[in][0] + i;
int ny = desll[in][1] + j;
if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny]) {
vis[nx][ny] = vis[i][j] + 1;
qu.push(make_pair(nx, ny));
}
}
}
printf("%d\n", mx - 1);
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,089 | 869,090 | u662513110 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
int y, x;
};
position mv[4] = {
{0, -1},
{1, 0},
{0, 1},
{-1, 0}}; // double euclidean(position first, position second){ return
// sqrt((second.x - first.x) * (second.x - first.x) + (second.y -
// first.y) * (second.y - first.y)); }
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + " ";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> dist(H, vector<int>(W, -1));
queue<position> pathes;
string space[H];
for (int i = 0; i < H; i++) {
cin >> space[i];
for (int j = 0; j < W; j++) {
if (space[i][j] == '#') {
pathes.push({i, j});
dist[i][j] = 0;
}
}
}
while (!pathes.empty()) {
auto top = pathes.front();
pathes.pop();
for (auto i : mv) {
position next = {top.y + i.y, top.x + i.x};
if (0 <= next.y && next.y < H && 0 <= next.x && next.x < H &&
dist[next.y][next.x] == -1) {
dist[next.y][next.x] = dist[top.y][top.x] + 1;
pathes.push({next.y, next.x});
}
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
int y, x;
};
position mv[4] = {
{0, -1},
{1, 0},
{0, 1},
{-1, 0}}; // double euclidean(position first, position second){ return
// sqrt((second.x - first.x) * (second.x - first.x) + (second.y -
// first.y) * (second.y - first.y)); }
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + " ";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> dist(H, vector<int>(W, -1));
queue<position> pathes;
string space[H];
for (int i = 0; i < H; i++) {
cin >> space[i];
for (int j = 0; j < W; j++) {
if (space[i][j] == '#') {
pathes.push({i, j});
dist[i][j] = 0;
}
}
}
while (!pathes.empty()) {
auto top = pathes.front();
pathes.pop();
for (auto i : mv) {
position next = {top.y + i.y, top.x + i.x};
if (0 <= next.y && next.y < H && 0 <= next.x && next.x < W &&
dist[next.y][next.x] == -1) {
dist[next.y][next.x] = dist[top.y][top.x] + 1;
pathes.push({next.y, next.x});
}
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, dist[i][j]);
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,097 | 869,098 | u115888500 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1003;
int n, m;
char a[N][N];
bool vis[N][N];
queue<pii> Q;
int di[] = {-1, 0, 0, 1};
int dj[] = {0, -1, 1, 0};
int main() {
std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '#') {
Q.push({i, j});
vis[i][j] = 1;
}
}
}
int res = 0;
while (!Q.empty()) {
int sz = Q.size();
while (sz--) {
auto cur = Q.front();
Q.pop();
for (int d = 0; d < 4; d++) {
int ni = cur.first + di[d];
int nj = cur.second + dj[d];
if (ni < 0 || ni >= n || nj < 0 || nj >= m || vis[ni][nj])
continue;
Q.push({ni, nj});
vis[ni][nj] = 1;
}
}
res++;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1003;
int n, m;
char a[N][N];
bool vis[N][N];
queue<pii> Q;
int di[] = {-1, 0, 0, 1};
int dj[] = {0, -1, 1, 0};
int main() {
std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '#') {
Q.push({i, j});
vis[i][j] = 1;
}
}
}
int res = 0;
while (!Q.empty()) {
int sz = Q.size();
while (sz--) {
auto cur = Q.front();
Q.pop();
for (int d = 0; d < 4; d++) {
int ni = cur.first + di[d];
int nj = cur.second + dj[d];
if (ni < 0 || ni >= n || nj < 0 || nj >= m || vis[ni][nj])
continue;
Q.push({ni, nj});
vis[ni][nj] = 1;
}
}
res++;
}
cout << res - 1 << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 869,099 | 869,100 | u362821344 | cpp |
p03053 | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = (0); i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
const int N = 1005;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int d[N][N], q[N * N][2], n, m, l, r, x, y, xx, yy;
char s[N][N];
int main() {
scanf("%d%d", &n, &m);
rep(i, 1, n) scanf("%s", s[i] + 1);
memset(d, -1, sizeof d);
rep(i, 1, n) rep(j, 1, n) if (s[i][j] == '#') {
d[i][j] = 0;
q[r][0] = i;
q[r++][1] = j;
}
int ans = 0;
while (l < r) {
x = q[l][0], y = q[l++][1];
ans = max(ans, d[x][y]);
REP(k, 4) {
xx = x + dx[k], yy = y + dy[k];
if (xx < 1 || xx > n || yy < 1 || yy > m)
continue;
if (d[xx][yy] != -1)
continue;
d[xx][yy] = d[x][y] + 1;
q[r][0] = xx;
q[r++][1] = yy;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = (0); i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
const int N = 1005;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int d[N][N], q[N * N][2], n, m, l, r, x, y, xx, yy;
char s[N][N];
int main() {
scanf("%d%d", &n, &m);
rep(i, 1, n) scanf("%s", s[i] + 1);
memset(d, -1, sizeof d);
rep(i, 1, n) rep(j, 1, m) if (s[i][j] == '#') {
d[i][j] = 0;
q[r][0] = i;
q[r++][1] = j;
}
int ans = 0;
while (l < r) {
x = q[l][0], y = q[l++][1];
ans = max(ans, d[x][y]);
REP(k, 4) {
xx = x + dx[k], yy = y + dy[k];
if (xx < 1 || xx > n || yy < 1 || yy > m)
continue;
if (d[xx][yy] != -1)
continue;
d[xx][yy] = d[x][y] + 1;
q[r][0] = xx;
q[r++][1] = yy;
}
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 869,107 | 869,108 | u603486542 | cpp |
p03053 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
const int diff[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int main(int argc, char *argv[]) {
int H, W, ans[1020][1020], aaa = 0;
string A[1020];
queue<pair<int, int>> que;
cin >> H >> W;
for (int i = 0; i < H; i++) {
cin >> A[i];
for (int j = 0; j < W; j++) {
if (A[i][j] == '#') {
que.push(make_pair(i, j));
}
ans[i][j] = 0;
}
}
while (!que.empty()) {
auto p = que.front();
que.pop();
int i = p.first;
int j = p.second;
for (int k = 0; k < 4; k++) {
int ii = i + diff[k][0];
int jj = j + diff[k][1];
if (ii >= 0 && jj >= 0 && ii < H && jj < W && A[ii][jj] == '.') {
A[ii][jj] = '#';
que.push(make_pair(ii, jj));
ans[ii][jj] = ans[i][i] + 1;
aaa = max(ans[ii][jj], aaa);
}
}
}
cout << aaa << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
const int diff[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int main(int argc, char *argv[]) {
int H, W, ans[1020][1020], aaa = 0;
string A[1020];
queue<pair<int, int>> que;
cin >> H >> W;
for (int i = 0; i < H; i++) {
cin >> A[i];
for (int j = 0; j < W; j++) {
if (A[i][j] == '#') {
que.push(make_pair(i, j));
}
ans[i][j] = 0;
}
}
while (!que.empty()) {
auto p = que.front();
que.pop();
int i = p.first;
int j = p.second;
for (int k = 0; k < 4; k++) {
int ii = i + diff[k][0];
int jj = j + diff[k][1];
if (ii >= 0 && jj >= 0 && ii < H && jj < W && A[ii][jj] == '.') {
A[ii][jj] = '#';
que.push(make_pair(ii, jj));
ans[ii][jj] = ans[i][j] + 1;
aaa = max(ans[ii][jj], aaa);
}
}
}
cout << aaa << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 869,113 | 869,114 | u801610392 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, inf = 10000, ans = 0;
char tmp;
cin >> h >> w;
vector<vector<int>> a(h + 2, vector<int>(w + 2));
for (int i = 0; i < h + 2; i++) {
a[i][0] = inf;
a[i][w + 1] = inf;
}
for (int j = 0; j < w + 2; j++) {
a[0][j] = inf;
a[h + 1][j] = inf;
}
for (int i = 1; i < h + 1; i++) {
for (int j = 1; j < w + 1; j++) {
cin >> tmp;
if (tmp == '#') {
a[i][j] = 0;
} else {
a[i][j] = min(a[i - 1][j], a[i][j - 1]) + 1;
}
}
}
for (int i = 1; i < h + 1; i++) {
for (int j = w; j > 0; j--) {
a[i][j] = min(min(a[i - 1][j], a[i][j + 1]) + 1, a[i][j]);
}
}
for (int i = h; i > 0; i--) {
for (int j = 0; j < w + 1; j++) {
a[i][j] = min(min(a[i + 1][j], a[i][j - 1]) + 1, a[i][j]);
}
}
for (int i = h; i > 0; i--) {
for (int j = w; j > 0; j--) {
a[i][j] = min(min(a[i + 1][j], a[i][j + 1]) + 1, a[i][j]);
ans = max(a[i][j], ans);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, inf = 10000, ans = 0;
char tmp;
cin >> h >> w;
vector<vector<int>> a(h + 2, vector<int>(w + 2));
for (int i = 0; i < h + 2; i++) {
a[i][0] = inf;
a[i][w + 1] = inf;
}
for (int j = 0; j < w + 2; j++) {
a[0][j] = inf;
a[h + 1][j] = inf;
}
for (int i = 1; i < h + 1; i++) {
for (int j = 1; j < w + 1; j++) {
cin >> tmp;
if (tmp == '#') {
a[i][j] = 0;
} else {
a[i][j] = min(a[i - 1][j], a[i][j - 1]) + 1;
}
}
}
for (int i = 1; i < h + 1; i++) {
for (int j = w; j > 0; j--) {
a[i][j] = min(min(a[i - 1][j], a[i][j + 1]) + 1, a[i][j]);
}
}
for (int i = h; i > 0; i--) {
for (int j = 1; j < w + 1; j++) {
a[i][j] = min(min(a[i + 1][j], a[i][j - 1]) + 1, a[i][j]);
}
}
for (int i = h; i > 0; i--) {
for (int j = w; j > 0; j--) {
a[i][j] = min(min(a[i + 1][j], a[i][j + 1]) + 1, a[i][j]);
ans = max(a[i][j], ans);
}
}
cout << ans << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 869,123 | 869,124 | u576357314 | cpp |
p03053 | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void printA(const vector<vector<char>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j];
}
cout << endl;
}
}
void printAns(const vector<vector<int>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << ' ';
}
cout << endl;
}
}
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h, vector<char>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> ans(h, vector<int>(w, INT_MAX));
// for right
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = 0; j < w; j++) {
if (a[i][j] == '#') {
hitBlack = true;
ans[i][j] = 0;
} else if (hitBlack) {
chmin(ans[i][j], ans[i][j - 1] + 1);
}
}
}
// for left
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = w - 1; j >= 0; j--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i][j + 1] + 1);
}
}
}
// for bottom
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = 0; i < h; i++) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i - 1][j] + 1);
}
}
}
// for top
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = h - 1; i >= 0; i--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i + 1][j] + 1);
}
}
}
printAns(ans);
int maxVal = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
chmax(maxVal, ans[i][j]);
}
}
cout << maxVal << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void printA(const vector<vector<char>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j];
}
cout << endl;
}
}
void printAns(const vector<vector<int>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << ' ';
}
cout << endl;
}
}
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h, vector<char>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> ans(h, vector<int>(w, INT_MAX));
// for right
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = 0; j < w; j++) {
if (a[i][j] == '#') {
hitBlack = true;
ans[i][j] = 0;
} else if (hitBlack) {
chmin(ans[i][j], ans[i][j - 1] + 1);
}
}
}
// for left
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = w - 1; j >= 0; j--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i][j + 1] + 1);
}
}
}
// for bottom
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = 0; i < h; i++) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i - 1][j] + 1);
}
}
}
// for top
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = h - 1; i >= 0; i--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i + 1][j] + 1);
}
}
}
// printAns(ans);
int maxVal = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
chmax(maxVal, ans[i][j]);
}
}
cout << maxVal << endl;
return 0;
} | [
"call.remove"
] | 869,129 | 869,130 | u784838174 | cpp |
p03053 | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void printA(const vector<vector<char>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j];
}
cout << endl;
}
}
void printAns(const vector<vector<int>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << ' ';
}
cout << endl;
}
}
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h, vector<char>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> ans(w, vector<int>(h, INT_MAX));
// for right
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = 0; j < w; j++) {
if (a[i][j] == '#') {
hitBlack = true;
ans[i][j] = 0;
} else if (hitBlack) {
chmin(ans[i][j], ans[i][j - 1] + 1);
}
}
}
// for left
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = w - 1; j >= 0; j--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i][j + 1] + 1);
}
}
}
// for bottom
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = 0; i < h; i++) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i - 1][j] + 1);
}
}
}
// for top
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = h - 1; i >= 0; i--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i + 1][j] + 1);
}
}
}
// printAns(ans);
int maxVal = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
chmax(maxVal, ans[i][j]);
}
}
cout << maxVal << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void printA(const vector<vector<char>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j];
}
cout << endl;
}
}
void printAns(const vector<vector<int>> &a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << ' ';
}
cout << endl;
}
}
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> a(h, vector<char>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> ans(h, vector<int>(w, INT_MAX));
// for right
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = 0; j < w; j++) {
if (a[i][j] == '#') {
hitBlack = true;
ans[i][j] = 0;
} else if (hitBlack) {
chmin(ans[i][j], ans[i][j - 1] + 1);
}
}
}
// for left
for (int i = 0; i < h; i++) {
bool hitBlack = false;
for (int j = w - 1; j >= 0; j--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i][j + 1] + 1);
}
}
}
// for bottom
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = 0; i < h; i++) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i - 1][j] + 1);
}
}
}
// for top
for (int j = 0; j < w; j++) {
bool hitBlack = false;
for (int i = h - 1; i >= 0; i--) {
if ((!hitBlack) && (ans[i][j] != INT_MAX)) {
hitBlack = true;
continue;
}
if (hitBlack) {
chmin(ans[i][j], ans[i + 1][j] + 1);
}
}
}
// printAns(ans);
int maxVal = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
chmax(maxVal, ans[i][j]);
}
}
cout << maxVal << endl;
return 0;
} | [] | 869,131 | 869,130 | u784838174 | cpp |
p03053 | #include <iostream>
struct point {
int x, y;
} p1[1000001], p2[1000001], *cur, *last;
int len1, len2;
char mp[1001][1001];
int main() {
int h, w;
std::cin >> h >> w;
cur = p2;
last = p1;
for (int i = 0; i < h; i++) {
std::cin >> mp[i];
for (int j = 0; mp[i][j] != '\0'; j++) {
if (mp[i][j] == '.')
continue;
p1[len1].x = i;
p1[len1++].y = j;
}
}
int r = 0;
while (true) {
len2 = 0;
for (int i = 0; i < len1; i++) {
int x = last[i].x, y = last[i].y;
if (y > 0 && mp[x][y - 1] == '.') {
cur[len2].x = x;
cur[len2++].y = y - 1;
mp[x][y - 1] = '#';
}
if (x > 0 && mp[x - 1][y] == '.') {
cur[len2].x = x - 1;
cur[len2++].y = y;
mp[x - 1][y] = '#';
}
if (y < h - 1 && mp[x][y + 1] == '.') {
cur[len2].x = x;
cur[len2++].y = y + 1;
mp[x][y + 1] = '#';
}
if (x < w - 1 && mp[x + 1][y] == '.') {
cur[len2].x = x + 1;
cur[len2++].y = y;
mp[x + 1][y] = '#';
}
}
std::swap(cur, last);
len1 = len2;
if (len1 == 0)
break;
r++;
}
std::cout << r << std::endl;
return 0;
}
| #include <iostream>
struct point {
int x, y;
} p1[1000001], p2[1000001], *cur, *last;
int len1, len2;
char mp[1001][1001];
int main() {
int h, w;
std::cin >> h >> w;
cur = p2;
last = p1;
for (int i = 0; i < h; i++) {
std::cin >> mp[i];
for (int j = 0; mp[i][j] != '\0'; j++) {
if (mp[i][j] == '.')
continue;
p1[len1].x = i;
p1[len1++].y = j;
}
}
int r = 0;
while (true) {
len2 = 0;
for (int i = 0; i < len1; i++) {
int x = last[i].x, y = last[i].y;
if (y > 0 && mp[x][y - 1] == '.') {
cur[len2].x = x;
cur[len2++].y = y - 1;
mp[x][y - 1] = '#';
}
if (x > 0 && mp[x - 1][y] == '.') {
cur[len2].x = x - 1;
cur[len2++].y = y;
mp[x - 1][y] = '#';
}
if (y < w - 1 && mp[x][y + 1] == '.') {
cur[len2].x = x;
cur[len2++].y = y + 1;
mp[x][y + 1] = '#';
}
if (x < h - 1 && mp[x + 1][y] == '.') {
cur[len2].x = x + 1;
cur[len2++].y = y;
mp[x + 1][y] = '#';
}
}
std::swap(cur, last);
len1 = len2;
if (len1 == 0)
break;
r++;
}
std::cout << r << std::endl;
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,137 | 869,138 | u339554233 | cpp |
p03053 |
// vim: set fdm=marker:
// {{{
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
// }}}
char A[1111][1111];
int main() {
int H, W;
cin >> H >> W;
for (int i = 0; i != H; i++) {
scanf("%s", A[i]);
}
set<pair<int, int>> S;
for (int i = 0; i != H; i++) {
for (int j = 0; j != W; j++) {
if (A[i][j] == '#') {
S.insert({i, j});
}
}
}
const int sx[] = {0, -1, 0, 1};
const int sy[] = {1, 0, -1, 0};
for (int ans = 0;; ans++) {
set<pair<int, int>> next;
for (auto p : S) {
for (int k = 0; k != 4; k++) {
int nx = sx[k] + p.first;
int ny = sy[k] + p.second;
if (nx < 0 || nx >= H)
continue;
if (ny < 0 || ny >= W)
continue;
if (A[nx][ny] != '.')
continue;
next.insert({nx, ny});
A[p.first][p.second] = '#';
}
}
S = next;
if (S.size() == 0) {
cout << ans << endl;
return 0;
}
}
return 0;
}
|
// vim: set fdm=marker:
// {{{
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
// }}}
char A[1111][1111];
int main() {
int H, W;
cin >> H >> W;
for (int i = 0; i != H; i++) {
scanf("%s", A[i]);
}
set<pair<int, int>> S;
for (int i = 0; i != H; i++) {
for (int j = 0; j != W; j++) {
if (A[i][j] == '#') {
S.insert({i, j});
}
}
}
const int sx[] = {0, -1, 0, 1};
const int sy[] = {1, 0, -1, 0};
for (int ans = 0;; ans++) {
set<pair<int, int>> next;
for (auto p : S) {
for (int k = 0; k != 4; k++) {
int nx = sx[k] + p.first;
int ny = sy[k] + p.second;
if (nx < 0 || nx >= H)
continue;
if (ny < 0 || ny >= W)
continue;
if (A[nx][ny] != '.')
continue;
next.insert({nx, ny});
A[nx][ny] = '#';
}
}
S = next;
if (S.size() == 0) {
cout << ans << endl;
return 0;
}
}
return 0;
}
| [
"assignment.variable.change",
"variable_access.subscript.index.change"
] | 869,141 | 869,142 | u839680500 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int main(void) {
int H, W;
cin >> H >> W;
vector<string> A(H);
REP(i, H) cin >> A[i];
int ans = 0;
queue<pair<int, int>> q;
vector<vector<bool>> used(H, vector<bool>(W, false));
REP(i, H) {
REP(j, W) {
if (A[i][j] == '#') {
q.push(make_pair(i, j));
used[i][j] = true;
}
}
}
while (1) {
ans++;
vector<pair<int, int>> nn;
while (q.size()) {
pair<int, int> p = q.front();
q.pop();
int x = p.fi;
int y = p.se;
// cout << x << " " << y << endl;
REP(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= W)
continue;
if (ny < 0 || ny >= H)
continue;
if (used[ny][nx])
continue;
// cout << " " << nx << " " << ny << endl;
used[ny][nx] = true;
A[ny][nx] = '#';
nn.pb(make_pair(nx, ny));
}
}
if (nn.size() == 0)
break;
REP(i, nn.size()) { q.push(nn[i]); }
}
cout << ans - 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int main(void) {
int H, W;
cin >> H >> W;
vector<string> A(H);
REP(i, H) cin >> A[i];
ll ans = 0;
queue<pair<int, int>> q;
vector<vector<bool>> used(H, vector<bool>(W, false));
REP(i, H) {
REP(j, W) {
if (A[i][j] == '#') {
q.push(make_pair(j, i));
used[i][j] = true;
}
}
}
while (1) {
ans++;
vector<pair<int, int>> nn;
while (q.size()) {
pair<int, int> p = q.front();
q.pop();
int x = p.fi;
int y = p.se;
// cout << x << " " << y << endl;
REP(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= W)
continue;
if (ny < 0 || ny >= H)
continue;
if (used[ny][nx])
continue;
// cout << " " << nx << " " << ny << endl;
used[ny][nx] = true;
A[ny][nx] = '#';
nn.pb(make_pair(nx, ny));
}
}
if (nn.size() == 0)
break;
REP(i, nn.size()) { q.push(nn[i]); }
}
cout << ans - 1 << endl;
return 0;
} | [
"variable_declaration.type.change",
"call.arguments.change",
"call.arguments.add"
] | 869,162 | 869,163 | u511344501 | cpp |
p03053 | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr long long MOD = 1000000007;
struct State {
int i, j, d;
};
int main() {
int H, W;
std::cin >> H >> W;
std::vector<std::vector<int>> a(H, std::vector<int>(W));
std::queue<State> q;
for (int i = 0; i < H; ++i) {
std::string str;
std::cin >> str;
for (int j = 0; j < W; ++j) {
if (str[j] == '#') {
a[i][j] = 0;
q.push({i, j, 0});
} else
a[i][j] = INT_MAX;
}
}
while (!q.empty()) {
auto state = q.front();
q.pop();
int i = state.i;
int j = state.j;
int d = state.d;
if (0 <= i - 1 && d + 1 < a[i - 1][j]) {
a[i - 1][j] = d + 1;
q.push({i - 1, j, d + 1});
}
if (0 <= j - 1 && d + 1 < a[i][j - 1]) {
a[i][j - 1] = d + 1;
q.push({i, j - 1, d + 1});
}
if (i + 1 < H && d + 1 < a[i + 1][j]) {
a[i + 1][j] = d + 1;
q.push({i + 1, j, d + 1});
}
if (j + 1 < H && d + 1 < a[i][j + 1]) {
a[i][j + 1] = d + 1;
q.push({i, j + 1, d + 1});
}
}
int ans = 0;
for (auto &v : a) {
for (auto val : v) {
ans = std::max(ans, val);
}
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr long long MOD = 1000000007;
struct State {
int i, j, d;
};
int main() {
int H, W;
std::cin >> H >> W;
std::vector<std::vector<int>> a(H, std::vector<int>(W));
std::queue<State> q;
for (int i = 0; i < H; ++i) {
std::string str;
std::cin >> str;
for (int j = 0; j < W; ++j) {
if (str[j] == '#') {
a[i][j] = 0;
q.push({i, j, 0});
} else
a[i][j] = INT_MAX;
}
}
while (!q.empty()) {
auto state = q.front();
q.pop();
int i = state.i;
int j = state.j;
int d = state.d;
if (0 <= i - 1 && d + 1 < a[i - 1][j]) {
a[i - 1][j] = d + 1;
q.push({i - 1, j, d + 1});
}
if (0 <= j - 1 && d + 1 < a[i][j - 1]) {
a[i][j - 1] = d + 1;
q.push({i, j - 1, d + 1});
}
if (i + 1 < H && d + 1 < a[i + 1][j]) {
a[i + 1][j] = d + 1;
q.push({i + 1, j, d + 1});
}
if (j + 1 < W && d + 1 < a[i][j + 1]) {
a[i][j + 1] = d + 1;
q.push({i, j + 1, d + 1});
}
}
int ans = 0;
for (auto &v : a) {
for (auto val : v) {
ans = std::max(ans, val);
}
}
std::cout << ans << std::endl;
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,164 | 869,165 | u866733412 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = int(1e5) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;
int n, m, used[1005][1005], d[1005][1005], timer;
char a[1005][1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
queue<pii> q;
memset(d, -1, sizeof(d));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if (a[i][j] == '#') {
d[i][j] = 0;
q.push({i, j});
}
}
}
while (!q.empty()) {
int x = q.front().fi, y = q.front().se;
q.pop();
if (x + 1 <= n && d[x + 1][y] == -1) {
d[x + 1][y] = d[x][y] + 1;
q.push({x + 1, y});
}
if (y + 1 <= m && d[x][y + 1] == -1) {
d[x][y + 1] = d[x][y] + 1;
q.push({x, y + 1});
}
if (x - 1 >= 1 && d[x - 1][y] == -1) {
d[x - 1][y] = d[x - 1][y] + 1;
q.push({x - 1, y});
}
if (y - 1 >= 1 && d[x][y - 1] == -1) {
d[x][y - 1] = d[x][y - 1] + 1;
q.push({x, y - 1});
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ans = max(ans, d[i][j]);
}
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = int(1e5) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;
int n, m, used[1005][1005], d[1005][1005], timer;
char a[1005][1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
queue<pii> q;
memset(d, -1, sizeof(d));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if (a[i][j] == '#') {
d[i][j] = 0;
q.push({i, j});
}
}
}
while (!q.empty()) {
int x = q.front().fi, y = q.front().se;
q.pop();
if (x + 1 <= n && d[x + 1][y] == -1) {
d[x + 1][y] = d[x][y] + 1;
q.push({x + 1, y});
}
if (y + 1 <= m && d[x][y + 1] == -1) {
d[x][y + 1] = d[x][y] + 1;
q.push({x, y + 1});
}
if (x - 1 >= 1 && d[x - 1][y] == -1) {
d[x - 1][y] = d[x][y] + 1;
q.push({x - 1, y});
}
if (y - 1 >= 1 && d[x][y - 1] == -1) {
d[x][y - 1] = d[x][y] + 1;
q.push({x, y - 1});
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ans = max(ans, d[i][j]);
}
}
cout << ans << "\n";
return 0;
}
| [
"expression.operation.binary.remove"
] | 869,168 | 869,169 | u829956284 | cpp |
p03050 | #include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar) \
for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF
#define debug(x) cout << #x << ": " << x << endl
#define arr1d(a, n) \
cout << #a << " : "; \
fr(_, 1, n) cout << a[_] << ' '; \
cout << endl;
#define arr1d0(a, n) \
cout << #a << " : "; \
rep(_, n) cout << a[_] << ' '; \
cout << endl;
#define arr2d(a, n, m) \
cout << #a << " :" << endl; \
fr(_, 1, n) { \
fr(__, 1, m) cout << a[_][__] << ' '; \
cout << endl; \
}
#define arr2d0(a, n, m) \
cout << #a << " :" << endl; \
rep(_, n) { \
rep(__, m) cout << a[_][__] << ' '; \
cout << endl; \
}
/*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
/*IIT Roorkee = <3 */
#define ull unsigned long long
#define ll long long
#define ld double
#define ui unsigned int
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define y0 yyyyyy0
auto clk = clock();
#define y1 yyyyyy1
#define BIT(n) (1 << (n))
#define SQR(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define LSOne(S) (S) & (-S)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
template <typename T> inline T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> string toStr(T x) {
stringstream st;
st << x;
string s;
st >> s;
return s;
}
template <class T> void splitStr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
inline int two(int n) { return 1 << n; }
inline int isOnBit(int n, int b) { return (n >> b) & 1; }
inline void onBit(int &n, int b) { n |= two(b); }
inline void offBit(int &n, int b) { n &= ~two(b); }
inline int lastBit(int n) { return n & (-n); }
inline int cntBit(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
#define INP "test.inp"
#define OUT "test.out"
#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 100000
#define MOD 1000000007
#define dec decr
// END OF COMPETITVE PROGRAMMING TEMPLATE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll modexp(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed;
cout << setprecision(9);
ll n;
cin >> n;
if (n == 1) {
cout << "0";
return 0;
}
ll x = (ll)(sqrt(n));
x++;
ll ans = 0;
for (ll i = 1; i <= x; i++) {
ll z = n - i;
if (z % i == 0) {
ll k = z / i;
if (n / k == n % k) {
ans += k;
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar) \
for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF
#define debug(x) cout << #x << ": " << x << endl
#define arr1d(a, n) \
cout << #a << " : "; \
fr(_, 1, n) cout << a[_] << ' '; \
cout << endl;
#define arr1d0(a, n) \
cout << #a << " : "; \
rep(_, n) cout << a[_] << ' '; \
cout << endl;
#define arr2d(a, n, m) \
cout << #a << " :" << endl; \
fr(_, 1, n) { \
fr(__, 1, m) cout << a[_][__] << ' '; \
cout << endl; \
}
#define arr2d0(a, n, m) \
cout << #a << " :" << endl; \
rep(_, n) { \
rep(__, m) cout << a[_][__] << ' '; \
cout << endl; \
}
/*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
/*IIT Roorkee = <3 */
#define ull unsigned long long
#define ll long long
#define ld double
#define ui unsigned int
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define y0 yyyyyy0
auto clk = clock();
#define y1 yyyyyy1
#define BIT(n) (1 << (n))
#define SQR(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define LSOne(S) (S) & (-S)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
template <typename T> inline T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> string toStr(T x) {
stringstream st;
st << x;
string s;
st >> s;
return s;
}
template <class T> void splitStr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
inline int two(int n) { return 1 << n; }
inline int isOnBit(int n, int b) { return (n >> b) & 1; }
inline void onBit(int &n, int b) { n |= two(b); }
inline void offBit(int &n, int b) { n &= ~two(b); }
inline int lastBit(int n) { return n & (-n); }
inline int cntBit(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
#define INP "test.inp"
#define OUT "test.out"
#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 100000
#define MOD 1000000007
#define dec decr
// END OF COMPETITVE PROGRAMMING TEMPLATE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll modexp(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed;
cout << setprecision(9);
ll n;
cin >> n;
if (n == 1) {
cout << "0";
return 0;
}
ll x = (ll)(sqrt(n));
x++;
ll ans = 0;
for (ll i = 1; i <= x; i++) {
ll z = n - i;
if (z % i == 0) {
ll k = z / i;
if (k != 0 && n / k == n % k) {
ans += k;
}
}
}
cout << ans;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 869,176 | 869,177 | u795058347 | cpp |
p03050 | #include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
ll n, ans;
int main() {
scanf("%lld", &n);
if (n == 1) {
printf("0\n");
return 0;
}
for (ll i = 2; i * i <= n; i++) {
if (n % i)
continue;
ll d = i;
if (n / (d - 1) * d == n)
ans += d - 1;
d = n / i;
if (n / (d - 1) * d == n)
ans += d - 1;
}
printf("%lld\n", ans + n - 1);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
ll n, ans;
int main() {
scanf("%lld", &n);
if (n == 1 || n == 2) {
printf("0\n");
return 0;
}
for (ll i = 2; i * i <= n; i++) {
if (n % i)
continue;
ll d = i;
if (n / (d - 1) * d == n)
ans += d - 1;
d = n / i;
if (n / (d - 1) * d == n)
ans += d - 1;
}
printf("%lld\n", ans + n - 1);
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 869,182 | 869,183 | u656762776 | cpp |
p03050 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int
using namespace std;
int main() {
ll ans = 0;
ll n;
cin >> n;
REP(i, int(sqrt(n)) + 1) {
if (n % (i + 1) == 0) {
ll m = n / (i + 1);
ll l = i + 1;
if (m != 1) {
if (n % (m - 1) == n / (m - 1)) {
ans += m - 1;
}
}
if (l != 1) {
if (n % (l - 1) == n / (n - 1)) {
ans += l - 1;
}
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int
using namespace std;
int main() {
ll ans = 0;
ll n;
cin >> n;
REP(i, int(sqrt(n)) + 1) {
if (n % (i + 1) == 0) {
ll m = n / (i + 1);
ll l = i + 1;
if (m != 1) {
if (n % (m - 1) == n / (m - 1)) {
ans += m - 1;
}
}
if (l != 1) {
if (n % (l - 1) == n / (l - 1)) {
ans += l - 1;
}
}
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,184 | 869,185 | u620059302 | cpp |
p03050 | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod = 1000000007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
//約数列挙ってpythonでできるの?
// n%m==n/m==x
// n==x*m+x
// n==x*(m+1),m>x
llint n, ans = 0, i;
cin >> n;
for (i = 1; i * i < n; i++) {
if (n % i == 0) {
ans += n / i - 1;
}
}
cout << ans << endl;
} | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod = 1000000007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
//約数列挙ってpythonでできるの?
// n%m==n/m==x
// n==x*m+x
// n==x*(m+1),m>x
llint n, ans = 0, i;
cin >> n;
for (i = 1; i * (i + 1) < n; i++) {
if (n % i == 0) {
ans += n / i - 1;
}
}
cout << ans << endl;
}
| [
"control_flow.loop.for.condition.change"
] | 869,186 | 869,187 | u483814783 | cpp |
p03051 | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 1 << 20 | 3, mod = 1e9 + 7;
int n, maxn, a[N], pre[N], s[N], s2[N], f[N];
poly v[N];
inline int Mod(int x) { return x >= mod ? x - mod : x; }
int main() {
n = read(), pre[0] = 1;
For(i, 1, n) {
a[i] = read(), a[i] = a[i - 1] ^ a[i], v[a[i]].pb(i);
pre[i] = pre[i - 1] + (a[i] == 0);
}
int ans = 0;
if (a[n] == 0) {
int x = 1;
For(i, 1, pre[n] - 2) x = x * 2 % mod;
ans = Mod(ans + x);
}
FOR(i, 1, 1 << 20) if (!v[i].empty()) {
f[0] = 1, s[0] = 1, s2[0] = pre[v[i][0]];
FOR(j, 1, siz(v[i])) {
f[i] = (1ll * s[j - 1] * pre[v[i][j]] + mod - s2[j]) % mod;
s[j] = Mod(s[j - 1] + f[i]),
s2[j] = (s2[j - 1] + 1ll * f[j] * pre[v[i][j]]) % mod;
}
if (a[n] == 0)
ans = Mod(ans + s[siz(v[i]) - 1]);
else if (a[n] == i)
ans = Mod(ans + f[siz(v[i]) - 1]);
}
printf("%d\n", ans);
} | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 1 << 20 | 3, mod = 1e9 + 7;
int n, maxn, a[N], pre[N], s[N], s2[N], f[N];
poly v[N];
inline int Mod(int x) { return x >= mod ? x - mod : x; }
int main() {
n = read(), pre[0] = 1;
For(i, 1, n) {
a[i] = read(), a[i] = a[i - 1] ^ a[i], v[a[i]].pb(i);
pre[i] = pre[i - 1] + (a[i] == 0);
}
int ans = 0;
if (a[n] == 0) {
int x = 1;
For(i, 1, pre[n] - 2) x = x * 2 % mod;
ans = Mod(ans + x);
}
FOR(i, 1, 1 << 20) if (!v[i].empty()) {
f[0] = 1, s[0] = 1, s2[0] = pre[v[i][0]];
FOR(j, 1, siz(v[i])) {
f[j] = (1ll * s[j - 1] * pre[v[i][j]] + mod - s2[j - 1] + 1) % mod;
s[j] = Mod(s[j - 1] + f[j]),
s2[j] = (s2[j - 1] + 1ll * f[j] * pre[v[i][j]]) % mod;
}
if (a[n] == 0)
ans = Mod(ans + s[siz(v[i]) - 1]);
else if (a[n] == i)
ans = Mod(ans + f[siz(v[i]) - 1]);
}
printf("%d\n", ans);
} | [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change",
"assignment.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,198 | 869,199 | u026342954 | cpp |
p03051 | #include <bits/stdc++.h>
#include <omp.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
typedef pair<string, string> pst;
typedef pair<pii, pii> piii;
typedef vector<piii> vpii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef pair<pld, pld> pldd;
typedef vector<pld> vpd;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define my_abs(a) (((a) >= 0) ? (a) : -(a))
#define mp(a, b) make_pair(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define MODIK(a) (a >= M ? a - M : a)
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cout << (#x) << " = " << x << endl;
#ifdef ART_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &operator>>(istream &in, pii &a) {
in >> a.first >> a.second;
return in;
}
ostream &operator<<(ostream &out, pii &a) {
out << a.first << ' ' << a.second;
return out;
}
istream &operator>>(istream &in, pld &a) {
in >> a.first >> a.second;
return in;
}
ostream &operator<<(ostream &out, pld &a) {
out << a.first << ' ' << a.second;
return out;
}
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void print(int a, int b, int n, vi h) {
ofstream cout("output.txt");
cout << SZ(h) << ' ' << a << ' ' << b << '\n';
for (int i = 0; i < SZ(h); ++i) {
cout << h[i] << ' ';
}
cout.close();
exit(0);
}
inline bool break_time(ld time) { return clock() > CLOCKS_PER_SEC * time; }
void bonds() {
ld price, nkd, kd, year;
int cnt;
cout << "price nkd kd cnt year\n";
cout << endl;
cin >> price >> nkd >> kd >> cnt >> year;
cout << 100 * ((1000 + kd * cnt - price * 10 - nkd) / (price * 10) / year);
}
ld get_rand_ld(ld l, ld r) {
uniform_real_distribution<double> gen(l, r);
return gen(rng);
}
bool may(int E, ld T) {
if (E < 0)
return 1;
double eps = get_rand_ld(0, 1);
return eps < exp(-E / T);
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef ART_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(10) << fixed;
smain();
#ifdef ART_HOME
cout << "\nTOTAL EXECUTIOn TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
const int N = 2e5 + 10, K = 2e3 + 10, B = 100, oo = 2e14, M = 1e9 + 7, LOG = 20;
const int M1 = 1000000093, x1 = 27162;
const int M2 = 1000000087, x2 = 241;
const ld pi = atan2(1, 0) * 2, EPS = 1e-9;
int MOD(int v, int M) {
v %= M;
if (v < 0)
v += M;
return v;
}
int stupid(vi kek) {
int n = SZ(kek);
int ans = 0;
for (int x = 0; x < B; ++x) {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans += cnt;
}
}
return ans;
}
void smain() {
int n;
cin >> n;
vi kek(n);
for (int i = 0; i < n; ++i)
cin >> kek[i];
// cout << stupid(kek);
// return;
int x = 0;
for (int v : kek)
x ^= v;
vi lel = kek;
for (int i = 1; i < n; ++i)
lel[i] ^= lel[i - 1];
int ans = 0;
if (x != 0) {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans = cnt;
}
} else {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans = cnt;
}
vpi segs;
int prev = 0;
cur = 0;
for (int i = 0; i < n; ++i) {
cur ^= kek[i];
if (!cur) {
segs.push_back(mp(prev, i));
prev = i + 1;
}
}
map<int, vi> vseg;
map<int, map<int, int>> hui;
for (int i = 0; i < SZ(segs); ++i) {
auto p = segs[i];
int l = p.first, r = p.second;
for (int j = l; j < r; ++j)
vseg[lel[r] ^ lel[j]].push_back(i), hui[lel[r] ^ lel[j]][i]++;
}
for (auto p : vseg) {
vi cur = p.second;
stable_sort(ALL(cur));
cur.erase(unique(ALL(cur)), cur.end());
vpi dp(SZ(cur));
for (int i = 0; i < SZ(dp); ++i)
dp[i].first = hui[p.first][cur[i]], dp[i].second = hui[p.first][cur[i]];
for (int i = 0; i + 1 < SZ(dp); ++i) {
int d = cur[i + 1] - cur[i];
{// open - yes
{// will close - yes
{// next person - block - Yes
dp[i + 1].second = MOD(dp[i + 1].second + dp[i].first * d, M);
}
{ // next person - block - No
dp[i + 1].first =
MOD(dp[i + 1].first +
dp[i].first * MOD((d - 1) * hui[p.first][cur[i + 1]], M),
M);
dp[i + 1].second =
MOD(dp[i + 1].first +
dp[i].first * MOD((d - 1) * hui[p.first][cur[i + 1]], M),
M);
}
}
{ // will close - no
dp[i + 1].first = MOD(dp[i + 1].first + dp[i].first, M);
}
}
{ // open - no
{ // next person - block - Yes
dp[i + 1].second = MOD(dp[i + 1].second + dp[i].second, M);
}
{ // next person - block - No
dp[i + 1].first =
MOD(dp[i + 1].first + dp[i].second * hui[p.first][cur[i + 1]], M);
dp[i + 1].second =
MOD(dp[i + 1].second + dp[i].second * hui[p.first][cur[i + 1]], M);
}
}
}
ans = MOD(ans + dp.back().first, M);
}
}
cout << ans;
}
| #include <bits/stdc++.h>
#include <omp.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
typedef pair<string, string> pst;
typedef pair<pii, pii> piii;
typedef vector<piii> vpii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef pair<pld, pld> pldd;
typedef vector<pld> vpd;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define my_abs(a) (((a) >= 0) ? (a) : -(a))
#define mp(a, b) make_pair(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define MODIK(a) (a >= M ? a - M : a)
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cout << (#x) << " = " << x << endl;
#ifdef ART_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &operator>>(istream &in, pii &a) {
in >> a.first >> a.second;
return in;
}
ostream &operator<<(ostream &out, pii &a) {
out << a.first << ' ' << a.second;
return out;
}
istream &operator>>(istream &in, pld &a) {
in >> a.first >> a.second;
return in;
}
ostream &operator<<(ostream &out, pld &a) {
out << a.first << ' ' << a.second;
return out;
}
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void print(int a, int b, int n, vi h) {
ofstream cout("output.txt");
cout << SZ(h) << ' ' << a << ' ' << b << '\n';
for (int i = 0; i < SZ(h); ++i) {
cout << h[i] << ' ';
}
cout.close();
exit(0);
}
inline bool break_time(ld time) { return clock() > CLOCKS_PER_SEC * time; }
void bonds() {
ld price, nkd, kd, year;
int cnt;
cout << "price nkd kd cnt year\n";
cout << endl;
cin >> price >> nkd >> kd >> cnt >> year;
cout << 100 * ((1000 + kd * cnt - price * 10 - nkd) / (price * 10) / year);
}
ld get_rand_ld(ld l, ld r) {
uniform_real_distribution<double> gen(l, r);
return gen(rng);
}
bool may(int E, ld T) {
if (E < 0)
return 1;
double eps = get_rand_ld(0, 1);
return eps < exp(-E / T);
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef ART_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(10) << fixed;
smain();
#ifdef ART_HOME
cout << "\nTOTAL EXECUTIOn TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
const int N = 2e5 + 10, K = 2e3 + 10, B = 100, oo = 2e14, M = 1e9 + 7, LOG = 20;
const int M1 = 1000000093, x1 = 27162;
const int M2 = 1000000087, x2 = 241;
const ld pi = atan2(1, 0) * 2, EPS = 1e-9;
int MOD(int v, int M) {
v %= M;
if (v < 0)
v += M;
return v;
}
int stupid(vi kek) {
int n = SZ(kek);
int ans = 0;
for (int x = 0; x < B; ++x) {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans += cnt;
}
}
return ans;
}
void smain() {
int n;
cin >> n;
vi kek(n);
for (int i = 0; i < n; ++i)
cin >> kek[i];
// cout << stupid(kek);
// return;
int x = 0;
for (int v : kek)
x ^= v;
vi lel = kek;
for (int i = 1; i < n; ++i)
lel[i] ^= lel[i - 1];
int ans = 0;
if (x != 0) {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans = cnt;
}
} else {
int cur = 0;
map<int, int> flex;
flex[cur] = 1;
for (int i = 0; i < n; ++i) {
int v = kek[i];
cur ^= v;
int cnt = flex[cur ^ x];
flex[cur] = MOD(flex[cur] + cnt, M);
if (i + 1 == n)
ans = cnt;
}
vpi segs;
int prev = 0;
cur = 0;
for (int i = 0; i < n; ++i) {
cur ^= kek[i];
if (!cur) {
segs.push_back(mp(prev, i));
prev = i + 1;
}
}
map<int, vi> vseg;
map<int, map<int, int>> hui;
for (int i = 0; i < SZ(segs); ++i) {
auto p = segs[i];
int l = p.first, r = p.second;
for (int j = l; j < r; ++j)
vseg[lel[r] ^ lel[j]].push_back(i), hui[lel[r] ^ lel[j]][i]++;
}
for (auto p : vseg) {
vi cur = p.second;
stable_sort(ALL(cur));
cur.erase(unique(ALL(cur)), cur.end());
vpi dp(SZ(cur));
for (int i = 0; i < SZ(dp); ++i)
dp[i].first = hui[p.first][cur[i]], dp[i].second = hui[p.first][cur[i]];
for (int i = 0; i + 1 < SZ(dp); ++i) {
int d = cur[i + 1] - cur[i];
{// open - yes
{// will close - yes
{// next person - block - Yes
dp[i + 1].second = MOD(dp[i + 1].second + dp[i].first * d, M);
}
{ // next person - block - No
dp[i + 1].first =
MOD(dp[i + 1].first +
dp[i].first * MOD((d - 1) * hui[p.first][cur[i + 1]], M),
M);
dp[i + 1].second =
MOD(dp[i + 1].second +
dp[i].first * MOD((d - 1) * hui[p.first][cur[i + 1]], M),
M);
}
}
{ // will close - no
dp[i + 1].first = MOD(dp[i + 1].first + dp[i].first, M);
}
}
{ // open - no
{ // next person - block - Yes
dp[i + 1].second = MOD(dp[i + 1].second + dp[i].second, M);
}
{ // next person - block - No
dp[i + 1].first =
MOD(dp[i + 1].first + dp[i].second * hui[p.first][cur[i + 1]], M);
dp[i + 1].second =
MOD(dp[i + 1].second + dp[i].second * hui[p.first][cur[i + 1]], M);
}
}
}
ans = MOD(ans + dp.back().first, M);
}
}
cout << ans;
}
| [
"assignment.value.change",
"call.arguments.change"
] | 869,200 | 869,201 | u350388631 | cpp |
p03051 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll kai(ll x, ll y, ll m) {
ll res = 1;
for (ll i = x - y + 1; i <= x; i++) {
res *= i;
res %= m;
}
return res;
}
ll mod_pow(ll x, ll y, ll m) {
ll res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
ll comb(ll x, ll y, ll m) {
if (y > x)
return 0;
return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}
const ll mod = 1000000007;
int n, x;
vector<int> vec[1050000];
ll d[500010];
ll ans;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
x ^= a;
vec[x].push_back(i);
}
if (x) {
ll cnt1 = 1, cnt2 = 1;
for (int j = 0; j < (int)vec[x].size(); j++) {
int p = 0;
if (j)
p = vec[x][j - 1];
int t = lower_bound(all(vec[0]), vec[x][j]) - lower_bound(all(vec[0]), p);
cnt2 = (cnt2 + cnt1 * t) % mod;
cnt1 = (cnt1 + cnt2) % mod;
}
cout << cnt2 << endl;
return 0;
}
for (int i = 1; i < (1 << 20); i++) {
if ((int)vec[i].size() == 0)
continue;
ll cnt1 = 0, cnt2 = 1;
for (int j = 0; j < (int)vec[i].size(); j++) {
int p = 0;
if (j)
p = vec[i][j - 1];
int t = lower_bound(all(vec[0]), vec[i][j]) - lower_bound(all(vec[0]), p);
cnt2 = (cnt2 + cnt1 * t) % mod;
cnt1 = (cnt1 + cnt2) % mod;
}
ans = (ans + cnt1) % mod;
}
ll cnt = 1;
for (int i = 1; i < (int)vec[0].size(); i++)
cnt = cnt * 2 % mod;
cout << (ans + cnt) % mod << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll kai(ll x, ll y, ll m) {
ll res = 1;
for (ll i = x - y + 1; i <= x; i++) {
res *= i;
res %= m;
}
return res;
}
ll mod_pow(ll x, ll y, ll m) {
ll res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
ll comb(ll x, ll y, ll m) {
if (y > x)
return 0;
return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}
const ll mod = 1000000007;
int n, x;
vector<int> vec[1050000];
ll d[500010];
ll ans;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
x ^= a;
vec[x].push_back(i);
}
if (x) {
ll cnt1 = 0, cnt2 = 1;
for (int j = 0; j < (int)vec[x].size(); j++) {
int p = 0;
if (j)
p = vec[x][j - 1];
int t = lower_bound(all(vec[0]), vec[x][j]) - lower_bound(all(vec[0]), p);
cnt2 = (cnt2 + cnt1 * t) % mod;
cnt1 = (cnt1 + cnt2) % mod;
}
cout << cnt2 << endl;
return 0;
}
for (int i = 1; i < (1 << 20); i++) {
if ((int)vec[i].size() == 0)
continue;
ll cnt1 = 0, cnt2 = 1;
for (int j = 0; j < (int)vec[i].size(); j++) {
int p = 0;
if (j)
p = vec[i][j - 1];
int t = lower_bound(all(vec[0]), vec[i][j]) - lower_bound(all(vec[0]), p);
cnt2 = (cnt2 + cnt1 * t) % mod;
cnt1 = (cnt1 + cnt2) % mod;
}
ans = (ans + cnt1) % mod;
}
ll cnt = 1;
for (int i = 1; i < (int)vec[0].size(); i++)
cnt = cnt * 2 % mod;
cout << (ans + cnt) % mod << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 869,204 | 869,203 | u277153875 | cpp |
p03051 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
#define cx real()
#define cy imag()
const ll INF = 1LL << 60;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
const ll NCK_MAX = 510000;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
UnionFind(ll n) : par(n, 1), rank(n, 0) {}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
template <typename T> class Graph {
struct edge {
ll to;
T cost;
};
struct edge_data {
ll from, to;
T cost;
};
ll v;
vector<vector<edge>> e, re;
vector<edge_data> ed;
vector<bool> used;
vector<ll> vs, cmp;
bool isDirected, isMinasEdge;
public:
Graph(ll _v, bool _isDirected = true, ll range_add = 0) {
// range_add 0:no / 1:in / 2:out / 3:in+out
//_v++;
v = _v, isDirected = _isDirected;
isMinasEdge = false;
e.resize(v), re.resize(v);
}
void add_edge(ll s, ll t, T cost = 1) {
e[s].push_back((edge){t, cost});
if (!isDirected)
e[t].push_back((edge){s, cost});
else
re[t].push_back((edge){s, cost});
ed.push_back((edge_data){s, t, cost});
if (cost < 0)
isMinasEdge = true;
}
vector<T> dijkstra(ll s) {
vector<T> d(v, INF);
d[s] = 0;
auto edge_cmp = [](const edge &a, const edge &b) {
return a.cost > b.cost;
};
priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp);
pq.push((edge){s, 0});
while (!pq.empty()) {
edge temp = pq.top();
pq.pop();
if (d[temp.to] < temp.cost)
continue;
for (const edge &next : e[temp.to]) {
T cost = temp.cost + next.cost;
if (d[next.to] > cost) {
d[next.to] = cost;
pq.push((edge){next.to, cost});
}
}
}
return d;
}
vector<T> bellmanford(ll s) {
vector<T> d(v, INF);
d[s] = 0;
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = d[temp.from] + temp.cost;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = d[temp.to] + temp.cost;
}
}
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = -INF;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = -INF;
}
}
return d;
}
vector<T> shortest_path(ll s) {
if (isMinasEdge)
return bellmanford(s);
else
return dijkstra(s);
}
T kruskal() {
// if (isDirected)
UnionFind uf(v);
auto edge_data_cmp = [](const edge_data &a, const edge_data &b) {
return a.cost < b.cost;
};
sort(ed.begin(), ed.end(), edge_data_cmp);
T ans = 0;
for (const edge_data &temp : ed) {
if (uf.isSame(temp.from, temp.to))
continue;
uf.merge(temp.from, temp.to);
ans += temp.cost;
}
return ans;
}
void scc_dfs(ll s) {
used[s] = true;
for (const edge &i : e[s])
if (!used[i.to])
scc_dfs(i.to);
vs.push_back(s);
}
void scc_rdfs(ll s, ll k) {
used[s] = true;
cmp[s] = k;
for (const edge &i : re[s])
if (!used[i.to])
scc_rdfs(i.to, k);
}
vector<ll> scc() {
used.resize(v);
fill(used.begin(), used.end(), false);
cmp.resize(v);
vs.clear();
for (ll i = 0; i < v; i++)
if (!used[i])
scc_dfs(i);
used.resize(v);
fill(used.begin(), used.end(), false);
ll k = 0;
for (ll i = vs.size() - 1; i >= 0; i--)
if (!used[vs[i]])
scc_rdfs(vs[i], k++);
return cmp;
}
};
class RollingHash {
vector<__int128> hash;
vector<__int128> pw;
int base;
const __int128 hashmod = (1ull << 61) - 1;
public:
RollingHash(string s, int base = 10007)
: base(base), hash(s.length() + 1, 0), pw(s.length() + 1, 1) {
for (int i = 0; i < s.length(); i++) {
hash[i + 1] = (hash[i] * base + s[i]) % hashmod;
pw[i + 1] = pw[i] * base % hashmod;
}
}
ll get(ll a, ll b) { // [a, b)
__int128 tmp = hashmod + hash[b] - hash[a] * pw[b - a] % hashmod;
if (tmp >= hashmod)
tmp -= hashmod;
return (ll)tmp;
}
};
ll n, a[500001], sum[500001], dp[500001], dp2[500001], zero[500001],
nxt[500001], ans;
ll get(ll a, ll b) { // (a, b]
return zero[b] - zero[a];
}
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]), sum[i] = sum[i - 1] xor a[i];
// for (ll i = 1; i <= n; i++) printf("%lld ", sum[i]); printf("\n");
if (sum[n] != 0) {
ll dp_0 = 1, dp_sum = 0, now = 0;
for (ll i = 1; i <= n; i++) {
now ^= a[i];
if (now == 0) {
dp_0 += dp_sum;
if (dp_0 >= mod)
dp_0 -= mod;
}
if (now == sum[n]) {
dp_sum += dp_0;
if (dp_sum >= mod)
dp_sum -= mod;
}
}
printf("%lld\n", dp_0);
} else {
for (ll i = 1; i <= n; i++)
zero[i] = zero[i - 1] + (sum[i] == 0 ? 1 : 0);
map<ll, ll> mp;
for (ll i = n - 1; i > 0; i--) {
if (mp.count(sum[i]) == 1) {
nxt[i] = mp[sum[i]];
} else {
nxt[i] = -1;
}
mp[sum[i]] = i;
}
for (ll i = 1; i < n; i++)
if (sum[i] != 0) {
if (dp[i] == 0)
dp[i] = 1, dp2[i] = 1;
ans += dp[i];
if (nxt[i] != -1) {
dp[nxt[i]] += (dp[i] + dp2[i] * get(i, nxt[i])) % mod;
if (dp[nxt[i]] >= mod)
dp[nxt[i]] -= mod;
dp2[nxt[i]] = dp2[i] + dp[i];
if (dp2[nxt[i]] >= mod)
dp2[nxt[i]] -= mod;
}
}
// for (ll i = 1; i < n; i++) printf("%lld ", dp[i]); printf("\n");
// for (ll i = 1; i < n; i++) printf("%lld ", nxt[i]); printf("\n");
// printf("%lld!\n", ans);
for (ll i = 0; i <= zero[n]; i += 2)
ans += nCk(zero[n], i, mod);
// for (ll i = 0; i <= zero[n]; i += 2) printf("%lld!!!\n", nCk(zero[n], i,
// mod));
printf("%lld\n", ans % mod);
}
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
#define cx real()
#define cy imag()
const ll INF = 1LL << 60;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
const ll NCK_MAX = 510000;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
UnionFind(ll n) : par(n, 1), rank(n, 0) {}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
template <typename T> class Graph {
struct edge {
ll to;
T cost;
};
struct edge_data {
ll from, to;
T cost;
};
ll v;
vector<vector<edge>> e, re;
vector<edge_data> ed;
vector<bool> used;
vector<ll> vs, cmp;
bool isDirected, isMinasEdge;
public:
Graph(ll _v, bool _isDirected = true, ll range_add = 0) {
// range_add 0:no / 1:in / 2:out / 3:in+out
//_v++;
v = _v, isDirected = _isDirected;
isMinasEdge = false;
e.resize(v), re.resize(v);
}
void add_edge(ll s, ll t, T cost = 1) {
e[s].push_back((edge){t, cost});
if (!isDirected)
e[t].push_back((edge){s, cost});
else
re[t].push_back((edge){s, cost});
ed.push_back((edge_data){s, t, cost});
if (cost < 0)
isMinasEdge = true;
}
vector<T> dijkstra(ll s) {
vector<T> d(v, INF);
d[s] = 0;
auto edge_cmp = [](const edge &a, const edge &b) {
return a.cost > b.cost;
};
priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp);
pq.push((edge){s, 0});
while (!pq.empty()) {
edge temp = pq.top();
pq.pop();
if (d[temp.to] < temp.cost)
continue;
for (const edge &next : e[temp.to]) {
T cost = temp.cost + next.cost;
if (d[next.to] > cost) {
d[next.to] = cost;
pq.push((edge){next.to, cost});
}
}
}
return d;
}
vector<T> bellmanford(ll s) {
vector<T> d(v, INF);
d[s] = 0;
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = d[temp.from] + temp.cost;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = d[temp.to] + temp.cost;
}
}
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = -INF;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = -INF;
}
}
return d;
}
vector<T> shortest_path(ll s) {
if (isMinasEdge)
return bellmanford(s);
else
return dijkstra(s);
}
T kruskal() {
// if (isDirected)
UnionFind uf(v);
auto edge_data_cmp = [](const edge_data &a, const edge_data &b) {
return a.cost < b.cost;
};
sort(ed.begin(), ed.end(), edge_data_cmp);
T ans = 0;
for (const edge_data &temp : ed) {
if (uf.isSame(temp.from, temp.to))
continue;
uf.merge(temp.from, temp.to);
ans += temp.cost;
}
return ans;
}
void scc_dfs(ll s) {
used[s] = true;
for (const edge &i : e[s])
if (!used[i.to])
scc_dfs(i.to);
vs.push_back(s);
}
void scc_rdfs(ll s, ll k) {
used[s] = true;
cmp[s] = k;
for (const edge &i : re[s])
if (!used[i.to])
scc_rdfs(i.to, k);
}
vector<ll> scc() {
used.resize(v);
fill(used.begin(), used.end(), false);
cmp.resize(v);
vs.clear();
for (ll i = 0; i < v; i++)
if (!used[i])
scc_dfs(i);
used.resize(v);
fill(used.begin(), used.end(), false);
ll k = 0;
for (ll i = vs.size() - 1; i >= 0; i--)
if (!used[vs[i]])
scc_rdfs(vs[i], k++);
return cmp;
}
};
class RollingHash {
vector<__int128> hash;
vector<__int128> pw;
int base;
const __int128 hashmod = (1ull << 61) - 1;
public:
RollingHash(string s, int base = 10007)
: base(base), hash(s.length() + 1, 0), pw(s.length() + 1, 1) {
for (int i = 0; i < s.length(); i++) {
hash[i + 1] = (hash[i] * base + s[i]) % hashmod;
pw[i + 1] = pw[i] * base % hashmod;
}
}
ll get(ll a, ll b) { // [a, b)
__int128 tmp = hashmod + hash[b] - hash[a] * pw[b - a] % hashmod;
if (tmp >= hashmod)
tmp -= hashmod;
return (ll)tmp;
}
};
ll n, a[500001], sum[500001], dp[500001], dp2[500001], zero[500001],
nxt[500001], ans;
ll get(ll a, ll b) { // (a, b]
return zero[b] - zero[a];
}
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]), sum[i] = sum[i - 1] xor a[i];
// for (ll i = 1; i <= n; i++) printf("%lld ", sum[i]); printf("\n");
if (sum[n] != 0) {
ll dp_0 = 1, dp_sum = 0, now = 0;
for (ll i = 1; i <= n; i++) {
now ^= a[i];
if (now == 0) {
dp_0 += dp_sum;
if (dp_0 >= mod)
dp_0 -= mod;
}
if (now == sum[n]) {
dp_sum += dp_0;
if (dp_sum >= mod)
dp_sum -= mod;
}
}
printf("%lld\n", dp_0);
} else {
for (ll i = 1; i <= n; i++)
zero[i] = zero[i - 1] + (sum[i] == 0 ? 1 : 0);
map<ll, ll> mp;
for (ll i = n - 1; i > 0; i--) {
if (mp.count(sum[i]) == 1) {
nxt[i] = mp[sum[i]];
} else {
nxt[i] = -1;
}
mp[sum[i]] = i;
}
for (ll i = 1; i < n; i++)
if (sum[i] != 0) {
if (dp[i] == 0)
dp[i] = 1, dp2[i] = 1;
ans += dp[i];
if (nxt[i] != -1) {
dp[nxt[i]] += (dp[i] + dp2[i] * get(i, nxt[i])) % mod;
if (dp[nxt[i]] >= mod)
dp[nxt[i]] -= mod;
dp2[nxt[i]] = dp2[i] + dp[nxt[i]];
if (dp2[nxt[i]] >= mod)
dp2[nxt[i]] -= mod;
}
}
// for (ll i = 1; i < n; i++) printf("%lld ", dp[i]); printf("\n");
// for (ll i = 1; i < n; i++) printf("%lld ", nxt[i]); printf("\n");
// printf("%lld!\n", ans);
for (ll i = 0; i <= zero[n]; i += 2)
ans += nCk(zero[n], i, mod);
// for (ll i = 0; i <= zero[n]; i += 2) printf("%lld!!!\n", nCk(zero[n], i,
// mod));
printf("%lld\n", ans % mod);
}
}
| [] | 869,205 | 869,206 | u820262277 | cpp |
p03051 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
scanf("%d", &A[i]);
vector<vector<int>> accum(1 << 20);
int now = 0;
vector<ll> zero(N + 1, 0);
for (int i = 0; i < N; i++) {
now ^= A[i];
accum[now].push_back(i + 1);
if (now == 0)
zero[i + 1]++;
}
for (int i = 0; i < N; i++) {
zero[i + 1] += zero[i];
}
ll mod = 1e9 + 7;
if (now > 0) {
int K = accum[now].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int i = 1; i <= K; i++) {
if (i == 1) {
dp0[i] = 1;
dp1[i] = 1;
} else {
ll n = zero[accum[now][i - 1]] - zero[accum[now][i - 2]];
dp0[i] = (dp0[i - 1] + n * dp1[i - 1]) % mod;
dp1[i] = (dp0[i - 1] + (n + 1) * dp1[i - 1]) % mod;
}
}
cout << dp1[K] % mod << endl;
} else {
ll ans = 1;
for (int i = 0; i < (int)accum[0].size() - 1; i++) {
ans = ans * 2 % mod;
}
for (int i = 1; i < (1 << 20); i++) {
if (accum[i].empty())
continue;
int K = accum[i].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int j = 1; j <= K; j++) {
if (j == 1) {
dp0[j] = 1;
dp1[j] = 1;
} else {
ll n = zero[accum[i][j - 1]] - zero[accum[i][j - 2]];
dp0[j] = (dp0[j - 1] + n * dp1[j - 1]) % mod;
dp1[j] = (dp0[j - 1] + (n + 1) * dp1[j - 1]) % mod;
}
}
ans += dp1[K];
}
cout << ans % mod << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
scanf("%d", &A[i]);
vector<vector<int>> accum(1 << 20);
int now = 0;
vector<ll> zero(N + 1, 0);
for (int i = 0; i < N; i++) {
now ^= A[i];
accum[now].push_back(i + 1);
if (now == 0)
zero[i + 1]++;
}
for (int i = 0; i < N; i++) {
zero[i + 1] += zero[i];
}
ll mod = 1e9 + 7;
if (now > 0) {
int K = accum[now].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int i = 1; i <= K; i++) {
if (i == 1) {
dp0[i] = 1;
dp1[i] = 1;
} else {
ll n = zero[accum[now][i - 1]] - zero[accum[now][i - 2]];
dp0[i] = (dp0[i - 1] + n * dp1[i - 1]) % mod;
dp1[i] = (dp0[i - 1] + (n + 1) * dp1[i - 1]) % mod;
}
}
cout << dp0[K] % mod << endl;
} else {
ll ans = 1;
for (int i = 0; i < (int)accum[0].size() - 1; i++) {
ans = ans * 2 % mod;
}
for (int i = 1; i < (1 << 20); i++) {
if (accum[i].empty())
continue;
int K = accum[i].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int j = 1; j <= K; j++) {
if (j == 1) {
dp0[j] = 1;
dp1[j] = 1;
} else {
ll n = zero[accum[i][j - 1]] - zero[accum[i][j - 2]];
dp0[j] = (dp0[j - 1] + n * dp1[j - 1]) % mod;
dp1[j] = (dp0[j - 1] + (n + 1) * dp1[j - 1]) % mod;
}
}
ans += dp1[K];
}
cout << ans % mod << endl;
}
return 0;
} | [
"identifier.change",
"io.output.change"
] | 869,209 | 869,210 | u548834738 | cpp |
p03051 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
scanf("%d", &A[i]);
vector<vector<int>> accum(1 << 20);
int now = 0;
vector<ll> zero(N + 1, 0);
for (int i = 0; i < N; i++) {
now ^= A[i];
accum[now].push_back(i + 1);
if (now == 0)
zero[i + 1]++;
}
for (int i = 0; i < N; i++) {
zero[i + 1] += zero[i];
}
ll mod = 1e9 + 7;
if (now > 0) {
int K = accum[now].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int i = 1; i <= K; i++) {
if (i == 1) {
dp0[i] = 1;
dp1[i] = 1;
} else {
ll n = zero[accum[now][i - 1]] - zero[accum[now][i - 2]];
dp0[i] = (dp0[i - 1] + n * dp1[i - 1]) % mod;
dp1[i] = (dp0[i - 1] + n * dp1[i - 1]) % mod;
}
}
cout << dp1[K] % mod << endl;
} else {
ll ans = 1;
for (int i = 0; i < (int)accum[0].size() - 1; i++) {
ans = ans * 2 % mod;
}
for (int i = 1; i < (1 << 20); i++) {
if (accum[i].empty())
continue;
int K = accum[i].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int j = 1; j <= K; j++) {
if (j == 1) {
dp0[j] = 1;
dp1[j] = 1;
} else {
ll n = zero[accum[i][j - 1]] - zero[accum[i][j - 2]];
dp0[j] = (dp0[j - 1] + n * dp1[j - 1]) % mod;
dp1[j] = (dp0[j - 1] + (n + 1) * dp1[j - 1]) % mod;
}
}
ans += dp1[K];
}
cout << ans % mod << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
scanf("%d", &A[i]);
vector<vector<int>> accum(1 << 20);
int now = 0;
vector<ll> zero(N + 1, 0);
for (int i = 0; i < N; i++) {
now ^= A[i];
accum[now].push_back(i + 1);
if (now == 0)
zero[i + 1]++;
}
for (int i = 0; i < N; i++) {
zero[i + 1] += zero[i];
}
ll mod = 1e9 + 7;
if (now > 0) {
int K = accum[now].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int i = 1; i <= K; i++) {
if (i == 1) {
dp0[i] = 1;
dp1[i] = 1;
} else {
ll n = zero[accum[now][i - 1]] - zero[accum[now][i - 2]];
dp0[i] = (dp0[i - 1] + n * dp1[i - 1]) % mod;
dp1[i] = (dp0[i - 1] + (n + 1) * dp1[i - 1]) % mod;
}
}
cout << dp0[K] % mod << endl;
} else {
ll ans = 1;
for (int i = 0; i < (int)accum[0].size() - 1; i++) {
ans = ans * 2 % mod;
}
for (int i = 1; i < (1 << 20); i++) {
if (accum[i].empty())
continue;
int K = accum[i].size();
vector<ll> dp0(K + 1, 0), dp1(K + 1, 0);
dp0[0] = 1;
for (int j = 1; j <= K; j++) {
if (j == 1) {
dp0[j] = 1;
dp1[j] = 1;
} else {
ll n = zero[accum[i][j - 1]] - zero[accum[i][j - 2]];
dp0[j] = (dp0[j - 1] + n * dp1[j - 1]) % mod;
dp1[j] = (dp0[j - 1] + (n + 1) * dp1[j - 1]) % mod;
}
}
ans += dp1[K];
}
cout << ans % mod << endl;
}
return 0;
} | [
"identifier.change",
"io.output.change"
] | 869,211 | 869,210 | u548834738 | cpp |
p03051 | #pragma GCC optimize("O3")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define eb emplace_back
#define ep emplace
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c), end(c)
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline void print(vector<T> v) {
for (T e : v)
cout << e << " ";
cout << endl;
}
template <class T> inline void print(pair<T, T> p) {
cout << "(" << p.first << "," << p.second << ") ";
}
template <class T> inline void print(vector<pair<T, T>> v) {
for (auto e : v)
print(e);
cout << endl;
}
void print(vector<vec> v) {
for (auto e : v) {
for (auto ee : e)
cout << ee << " ";
cout << endl;
}
}
void print(map<int, int> mp) {
for (auto e : mp)
cout << e.first << " " << e.second << endl;
cout << endl;
}
const ll MOD = 1e9 + 7;
const int N = 500000;
template <ll Modulus> class modint {
using u64 = ll;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept
: a(((x % Modulus) + Modulus) % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
#define mint modint<MOD>
mint inv[N], comb[N], prd[N], invprd[N];
void calc_inv() {
inv[1] = 1;
rep2(i, 2, N - 1) { inv[i] = inv[MOD % i] * (-MOD / i); }
return;
}
void calc_product() {
prd[0] = prd[1] = 1;
invprd[0] = invprd[1] = 1;
rep2(i, 2, N - 1) {
prd[i] = prd[i - 1] * i;
invprd[i] = inv[i] * invprd[i - 1];
}
return;
}
mint cmb(int a, int b) {
if (a < b)
return 0;
if (a < 0 || b < 0)
return 0;
return {prd[a] * invprd[b] * invprd[a - b]};
}
mint modpow(mint x, ll n) {
if (n == 0)
return 1;
mint res = modpow(x * x, n / 2);
if (n & 1)
res = res * x;
return res;
}
void calc() {
calc_inv();
calc_product();
}
main() {
ios calc();
ll n;
cin >> n;
vec a;
rep(i, n) { a.pb(in()); }
map<int, mint> mp;
int xr = 0;
map<int, mint> mp2;
map<int, int> mp3;
int cnt = 0;
rep(i, n) {
xr ^= a[i];
mp2[xr] = 1;
}
mp2[0] = 1;
xr = 0;
rep(i, n) {
xr ^= a[i];
if (xr) {
mp2[xr] += mp[xr] * (cnt - mp3[xr]);
mp3[xr] = cnt;
mp[xr] += mp2[xr];
} else {
cnt++;
}
}
mint ans;
if (xr) {
ans = mp2[xr];
} else {
for (auto e : mp) {
if (e.first)
ans += e.second;
}
ans += modpow(2, cnt - 1);
}
cout << ans.a << endl;
} | #pragma GCC optimize("O3")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define eb emplace_back
#define ep emplace
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c), end(c)
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline void print(vector<T> v) {
for (T e : v)
cout << e << " ";
cout << endl;
}
template <class T> inline void print(pair<T, T> p) {
cout << "(" << p.first << "," << p.second << ") ";
}
template <class T> inline void print(vector<pair<T, T>> v) {
for (auto e : v)
print(e);
cout << endl;
}
void print(vector<vec> v) {
for (auto e : v) {
for (auto ee : e)
cout << ee << " ";
cout << endl;
}
}
void print(map<int, int> mp) {
for (auto e : mp)
cout << e.first << " " << e.second << endl;
cout << endl;
}
const ll MOD = 1e9 + 7;
const int N = 500000;
template <ll Modulus> class modint {
using u64 = ll;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept
: a(((x % Modulus) + Modulus) % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
#define mint modint<MOD>
mint inv[N], comb[N], prd[N], invprd[N];
void calc_inv() {
inv[1] = 1;
rep2(i, 2, N - 1) { inv[i] = inv[MOD % i] * (-MOD / i); }
return;
}
void calc_product() {
prd[0] = prd[1] = 1;
invprd[0] = invprd[1] = 1;
rep2(i, 2, N - 1) {
prd[i] = prd[i - 1] * i;
invprd[i] = inv[i] * invprd[i - 1];
}
return;
}
mint cmb(int a, int b) {
if (a < b)
return 0;
if (a < 0 || b < 0)
return 0;
return {prd[a] * invprd[b] * invprd[a - b]};
}
mint modpow(mint x, ll n) {
if (n == 0)
return 1;
mint res = modpow(x * x, n / 2);
if (n & 1)
res = res * x;
return res;
}
void calc() {
calc_inv();
calc_product();
}
main() {
calc();
ll n;
cin >> n;
vec a;
rep(i, n) { a.pb(in()); }
map<int, mint> mp;
int xr = 0;
map<int, mint> mp2;
map<int, int> mp3;
int cnt = 0;
rep(i, n) {
xr ^= a[i];
mp2[xr] = 1;
}
mp2[0] = 1;
xr = 0;
rep(i, n) {
xr ^= a[i];
if (xr) {
mp2[xr] += mp[xr] * (cnt - mp3[xr]);
mp3[xr] = cnt;
mp[xr] += mp2[xr];
} else {
cnt++;
}
}
mint ans;
if (xr) {
ans = mp2[xr];
} else {
for (auto e : mp) {
if (e.first)
ans += e.second;
}
ans += modpow(2, cnt - 1);
}
cout << ans.a << endl;
}
| [] | 869,228 | 869,229 | u495699318 | cpp |
p03051 | #include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter {
static tuple<H, T...> r(istream &i) {
H v;
i >> v;
return tuple_cat(tuple<H>(v),
TupleReaderWriter<sizeof...(T) - 1, T...>::r(i));
}
static void w(ostream &o, tuple<H, T...> &t, string d) {
TupleReaderWriter<I - 1, H, T...>::w(o, t, d);
o << d << get<I>(t);
}
};
template <class H, class... T> struct TupleReaderWriter<0, H, T...> {
static tuple<H, T...> r(istream &i) {
H v;
i >> v;
return tuple<H>(v);
}
static void w(ostream &o, tuple<H, T...> &t, string d) { o << get<0>(t); }
};
template <class... T> istream &operator>>(istream &i, tuple<T...> &t) {
t = TupleReaderWriter<sizeof...(T), T...>::r(i);
return i;
}
template <class... T> ostream &operator<<(ostream &o, tuple<T...> &t) {
string delim = " ";
TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim);
return o;
}
template <typename T>
using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
const i64 MOD = 1e9 + 7;
// O(log a)
int64_t powmod(int64_t a, int64_t p) {
int64_t value = 1;
for (int64_t mul = a; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
if (p & 1)
value = (value * mul) % MOD;
}
return value;
}
int64_t invmod(int64_t x) { return powmod(x, MOD - 2); }
struct int_m {
static int64_t mod;
int64_t v;
int_m() {}
int_m(int64_t x) : v(x) {}
int_m operator+(const int_m &y) { return (v + y.v) % mod; }
int_m operator-(const int_m &y) { return (v - y.v + mod) % mod; }
int_m operator*(const int_m &y) { return (v * y.v) % mod; }
int_m operator/(const int_m &y) { return (v * invmod(y.v)) % mod; }
void operator+=(const int_m &y) { *this = *this + y; }
void operator-=(const int_m &y) { *this = *this - y; }
void operator*=(const int_m &y) { *this = *this * y; }
void operator/=(const int_m &y) { *this = *this / y; }
friend istream &operator>>(istream &ist, int_m &m) { return ist >> m.v; }
friend ostream &operator<<(ostream &ost, int_m &m) { return ost << m.v; }
};
int64_t int_m::mod = MOD;
int main() {
int N;
cin >> N;
vector<i64> A(N), X(N), zeros(N, 0);
for (auto &x : A)
cin >> x;
for (int i = 0; i < N; i++) {
X[i] = A[i];
if (i)
X[i] ^= X[i - 1];
if (X[i] == 0)
zeros[i]++;
if (i)
zeros[i] += zeros[i - 1];
}
// 値v -> (最終位置, 最後に取ったのが0の場合の数, 最後に取ったのがvの場合の数)
map<i64, tuple<int, int_m, int_m>> m;
for (int i = 0; i < N - 1; i++) {
if (X[i] == 0)
continue;
if (!m.count(X[i])) {
m[X[i]] = make_tuple(i, 1, 1);
} else {
int j;
int_m n0, nv;
tie(j, n0, nv) = m[X[i]];
m[X[i]] = make_tuple(i,
n0 + nv * (zeros[i] - zeros[j]), // そのまま + 0取る
n0 + nv * (zeros[i] - zeros[j]) +
nv); // そのまま + V取る + 0取りV取る
}
}
int_m ans = 0;
if (X[N - 1] == 0) {
int num = -1;
for (int i = 0; i < N; i++) {
if (X[i] == 0)
num++;
}
ans += powmod(2, num);
for (auto x : m) {
int j;
int_m n0, nv;
tie(j, n0, nv) = x.second;
ans += nv;
}
} else {
int j;
int_m n0, nv;
tie(j, n0, nv) = m[X[N - 1]];
ans += n0 + nv * (zeros[N - 1] - zeros[j]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter {
static tuple<H, T...> r(istream &i) {
H v;
i >> v;
return tuple_cat(tuple<H>(v),
TupleReaderWriter<sizeof...(T) - 1, T...>::r(i));
}
static void w(ostream &o, tuple<H, T...> &t, string d) {
TupleReaderWriter<I - 1, H, T...>::w(o, t, d);
o << d << get<I>(t);
}
};
template <class H, class... T> struct TupleReaderWriter<0, H, T...> {
static tuple<H, T...> r(istream &i) {
H v;
i >> v;
return tuple<H>(v);
}
static void w(ostream &o, tuple<H, T...> &t, string d) { o << get<0>(t); }
};
template <class... T> istream &operator>>(istream &i, tuple<T...> &t) {
t = TupleReaderWriter<sizeof...(T), T...>::r(i);
return i;
}
template <class... T> ostream &operator<<(ostream &o, tuple<T...> &t) {
string delim = " ";
TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim);
return o;
}
template <typename T>
using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
const i64 MOD = 1e9 + 7;
// O(log a)
int64_t powmod(int64_t a, int64_t p) {
int64_t value = 1;
for (int64_t mul = a; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
if (p & 1)
value = (value * mul) % MOD;
}
return value;
}
int64_t invmod(int64_t x) { return powmod(x, MOD - 2); }
struct int_m {
static int64_t mod;
int64_t v;
int_m() {}
int_m(int64_t x) : v(x) {}
int_m operator+(const int_m &y) { return (v + y.v) % mod; }
int_m operator-(const int_m &y) { return (v - y.v + mod) % mod; }
int_m operator*(const int_m &y) { return (v * y.v) % mod; }
int_m operator/(const int_m &y) { return (v * invmod(y.v)) % mod; }
void operator+=(const int_m &y) { *this = *this + y; }
void operator-=(const int_m &y) { *this = *this - y; }
void operator*=(const int_m &y) { *this = *this * y; }
void operator/=(const int_m &y) { *this = *this / y; }
friend istream &operator>>(istream &ist, int_m &m) { return ist >> m.v; }
friend ostream &operator<<(ostream &ost, int_m &m) { return ost << m.v; }
};
int64_t int_m::mod = MOD;
int main() {
int N;
cin >> N;
vector<i64> A(N), X(N), zeros(N, 0);
for (auto &x : A)
cin >> x;
for (int i = 0; i < N; i++) {
X[i] = A[i];
if (i)
X[i] ^= X[i - 1];
if (X[i] == 0)
zeros[i]++;
if (i)
zeros[i] += zeros[i - 1];
}
// 値v -> (最終位置, 最後に取ったのが0の場合の数, 最後に取ったのがvの場合の数)
map<i64, tuple<int, int_m, int_m>> m;
for (int i = 0; i < N; i++) {
if (X[i] == 0)
continue;
if (!m.count(X[i])) {
m[X[i]] = make_tuple(i, 1, 1);
} else {
int j;
int_m n0, nv;
tie(j, n0, nv) = m[X[i]];
m[X[i]] = make_tuple(i,
n0 + nv * (zeros[i] - zeros[j]), // そのまま + 0取る
n0 + nv * (zeros[i] - zeros[j]) +
nv); // そのまま + V取る + 0取りV取る
}
}
int_m ans = 0;
if (X[N - 1] == 0) {
int num = -1;
for (int i = 0; i < N; i++) {
if (X[i] == 0)
num++;
}
ans += powmod(2, num);
for (auto x : m) {
int j;
int_m n0, nv;
tie(j, n0, nv) = x.second;
ans += nv;
}
} else {
int j;
int_m n0, nv;
tie(j, n0, nv) = m[X[N - 1]];
ans += n0 + nv * (zeros[N - 1] - zeros[j]);
}
cout << ans << endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 869,233 | 869,234 | u936555566 | cpp |
p03051 | #include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;
int modPow(int a, int p) {
if (p == 0)
return 1;
long long half = modPow(a, p / 2);
long long res = (half * half) % MOD;
if (p % 2)
res = (res * a) % MOD;
return res;
}
int main() {
int N;
while (cin >> N) {
vector<int> A(N);
for (auto &t : A)
cin >> t;
vector<int> B(N + 1, 0);
for (int i = 0; i < N; i++)
B[i + 1] = B[i] ^ A[i];
vector<int> checked0(1 << 20, 0);
vector<vector<int>> seq(1 << 20, vector<int>());
int cnt0 = 0;
long long res = 0;
if (B.back() == 0) {
for (auto &t : B) {
if (t == 0)
++cnt0;
else {
if (checked0[t] != cnt0) {
seq[t].push_back(cnt0 - checked0[t]);
seq[t].push_back(1);
checked0[t] = cnt0;
} else {
++seq[t].back();
}
}
}
for (int i = 0; i < (1 << 20); i++) {
seq[i].push_back(cnt0 - checked0[i]);
}
res = modPow(2, seq[0][0] - 2);
for (int i = 1; i < (1 << 20); i++) {
if (seq[i].size() == 1)
continue;
long long num0 = 1, num1 = 0;
for (int j = 1; j < seq[i].size(); j += 2) {
num1 += num0 * seq[i][j];
num1 %= MOD;
num0 += num1 * seq[i][j + 1];
num0 %= MOD;
}
res = (res + num1) % MOD;
}
} else {
long long num0 = 1, num1 = 0;
for (auto &t : B) {
if (t == 0) {
num0 = (num0 + num1) % MOD;
} else if (t == B.back()) {
num1 = (num0 + num1) % MOD;
}
}
res = num1;
}
cout << res << endl;
}
} | #include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;
int modPow(int a, int p) {
if (p == 0)
return 1;
long long half = modPow(a, p / 2);
long long res = (half * half) % MOD;
if (p % 2)
res = (res * a) % MOD;
return res;
}
int main() {
int N;
while (cin >> N) {
vector<int> A(N);
for (auto &t : A)
cin >> t;
vector<int> B(N + 1, 0);
for (int i = 0; i < N; i++)
B[i + 1] = B[i] ^ A[i];
vector<int> checked0(1 << 20, 0);
vector<vector<int>> seq(1 << 20, vector<int>());
int cnt0 = 0;
long long res = 0;
if (B.back() == 0) {
for (auto &t : B) {
if (t == 0)
++cnt0;
else {
if (checked0[t] != cnt0) {
seq[t].push_back(cnt0 - checked0[t]);
seq[t].push_back(1);
checked0[t] = cnt0;
} else {
++seq[t].back();
}
}
}
for (int i = 0; i < (1 << 20); i++) {
seq[i].push_back(cnt0 - checked0[i]);
}
res = modPow(2, seq[0][0] - 2);
for (int i = 1; i < (1 << 20); i++) {
if (seq[i].size() == 1)
continue;
long long num0 = 1, num1 = 0;
for (int j = 1; j < seq[i].size(); j += 2) {
num1 += num0 * seq[i][j];
num1 %= MOD;
num0 += num1 * seq[i][j + 1];
num0 %= MOD;
}
res = (res + num1) % MOD;
}
} else {
long long num0 = 1, num1 = 0;
for (auto &t : B) {
if (t == 0) {
num0 = (num0 + num1) % MOD;
} else if (t == B.back()) {
num1 = (num0 + num1) % MOD;
}
}
res = num0;
}
cout << res << endl;
}
} | [
"assignment.value.change",
"identifier.change"
] | 869,240 | 869,241 | u002023395 | cpp |
p03051 | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// std::vector Declaration
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
// std::vector Initialization
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename U> void fill_all(T &arr, const U &v) {
for (auto &i : arr)
fill_all(i, v);
}
// std::vector Debug
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::pair Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
// std::set Debug
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::map Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
os << "{";
bool a = 1;
for (auto e : mp) {
os << (a ? "" : " ");
os << e.first << ":" << e.second;
a = 0;
}
os << "}";
return os;
}
// std::tuple Debug
template <int N, class Tuple> void out(ostream &os, const Tuple &t) {}
template <int N, class Tuple, class H, class... Ts>
void out(ostream &os, const Tuple &t) {
if (N)
os << " ";
os << get<N>(t);
out<N + 1, Tuple, Ts...>(os, t);
}
template <class... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &t) {
os << "(";
out<0, tuple<Ts...>, Ts...>(os, t);
os << ")";
return os;
}
// Debug
#define DUMP(x) cout << #x << " = " << (x) << endl
struct edge {
int to, cost;
};
const LL LINF = 1LL << 60;
const int IINF = 1 << 30;
const LL MOD = 1e9 + 7;
template <typename Type, typename Operators> struct AlgStruct {
Type x;
template <typename... Args> AlgStruct(Args... args) : x(args...) {}
template <typename... Args> decltype(auto) operator[](Args... args) {
return x.operator[](args...);
}
AlgStruct &operator=(const AlgStruct &value) & = default;
template <typename... Args> static const AlgStruct idAdd(Args... args) {
return Operators::IdAdd(args...);
}
template <typename... Args> static const AlgStruct idMul(Args... args) {
return Operators::IdMul(args...);
}
const AlgStruct operator+() const { return *this; }
const AlgStruct operator-() const { return Operators::Opposite(x); }
const AlgStruct reciprocal() const { return Operators::Reciprocal(x); }
AlgStruct &operator+=(const AlgStruct &rhs) {
x = Operators::Add(x, rhs.x);
return *this;
}
AlgStruct &operator-=(const AlgStruct &rhs) {
*this += -rhs;
return *this;
}
AlgStruct &operator*=(const AlgStruct &rhs) {
x = Operators::Mul(x, rhs.x);
return *this;
}
AlgStruct &operator/=(const AlgStruct &rhs) {
return *this *= rhs.reciprocal();
}
const AlgStruct operator+(const AlgStruct &rhs) const {
return AlgStruct(*this) += rhs;
}
const AlgStruct operator-(const AlgStruct &rhs) const {
return AlgStruct(*this) -= rhs;
}
const AlgStruct operator*(const AlgStruct &rhs) const {
return AlgStruct(*this) *= rhs;
}
const AlgStruct operator/(const AlgStruct &rhs) const {
return AlgStruct(*this) /= rhs;
}
const AlgStruct power(long long n) const { return Operators::Power(x, n); }
bool operator<(const AlgStruct &rhs) const {
return Operators::Less(x, rhs.x);
}
bool operator>(const AlgStruct &rhs) const { return rhs < *this; }
bool operator<=(const AlgStruct &rhs) const { return !(*this > rhs); }
bool operator>=(const AlgStruct &rhs) const { return !(*this < rhs); }
bool operator==(const AlgStruct &rhs) const {
return !(*this < rhs) && !(*this > rhs);
}
bool operator!=(const AlgStruct &rhs) const { return !(*this == rhs); }
};
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator+(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) + rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator-(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) - rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator*(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) * rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator/(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) / rhs;
}
template <typename Type, typename Operators>
bool operator<(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) < rhs;
}
template <typename Type, typename Operators>
bool operator>(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) > rhs;
}
template <typename Type, typename Operators>
bool operator<=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) <= rhs;
}
template <typename Type, typename Operators>
bool operator>=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) >= rhs;
}
template <typename Type, typename Operators>
bool operator==(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) == rhs;
}
template <typename Type, typename Operators>
bool operator!=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) != rhs;
}
template <typename Type, typename Operators>
auto &operator<<(ostream &s, const AlgStruct<Type, Operators> &value) {
s << value.x;
return s;
}
template <typename T, T mod> struct GaloisFieldOperators {
static T Add(T lhs, T rhs) { return (lhs + rhs) % mod; };
static T Mul(T lhs, T rhs) { return (lhs * rhs) % mod; };
static T IdAdd() { return 0; };
static T IdMul() { return 1; };
static T Opposite(T value) { return ((-value % mod) + mod) % mod; };
static bool Less(T lhs, T rhs) { return lhs < rhs; };
static T Power(T value, long long n) {
T res = IdMul();
while (n > 0) {
if (n & 1)
res = Mul(res, value);
value = Mul(value, value);
n >>= 1;
}
return res;
}
static T Reciprocal(T value) { return Power(value, mod - 2); }
};
using GaloisField = AlgStruct<long long, GaloisFieldOperators<long long, MOD>>;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
vector<int> s(N + 1);
for (int i = 0; i < N; ++i) {
s[i + 1] = s[i] ^ a[i];
}
if (s[N] != 0) {
int d = s[N];
vector<LL> p;
int cnt = 0;
for (int i = 0; i < N + 1; ++i) {
if (s[i] == d) {
p.push_back(cnt);
} else if (s[i] == 0) {
++cnt;
}
}
int D = p.size();
vector<GaloisField> dp(D + 1), sum0(D + 1), sum1(D + 1);
for (int i = 0; i < D; ++i) {
dp[i + 1] = 1LL - sum1[i] + p[i] * sum0[i];
sum0[i + 1] = sum0[i] + dp[i + 1];
sum1[i + 1] = sum1[i] + dp[i + 1] * p[i];
}
GaloisField ans = dp[D];
cout << ans << endl;
}
else {
const int dmax = 1 << 3;
vector<vector<LL>> p(dmax + 1);
int cnt = 0;
for (int i = 0; i < N + 1; ++i) {
if (s[i] == 0) {
++cnt;
} else {
p[s[i]].push_back(cnt);
}
}
GaloisField ans = GaloisField(2).power(cnt - 2);
for (int d = 1; d < dmax + 1; ++d) {
int D = p[d].size();
vector<GaloisField> dp(D + 1), sum0(D + 1), sum1(D + 1);
for (int i = 0; i < D; ++i) {
dp[i + 1] = 1LL - sum1[i] + p[d][i] * sum0[i];
sum0[i + 1] = sum0[i] + dp[i + 1];
sum1[i + 1] = sum1[i] + dp[i + 1] * p[d][i];
ans += dp[i + 1];
}
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// std::vector Declaration
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
// std::vector Initialization
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename U> void fill_all(T &arr, const U &v) {
for (auto &i : arr)
fill_all(i, v);
}
// std::vector Debug
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::pair Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
// std::set Debug
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::map Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
os << "{";
bool a = 1;
for (auto e : mp) {
os << (a ? "" : " ");
os << e.first << ":" << e.second;
a = 0;
}
os << "}";
return os;
}
// std::tuple Debug
template <int N, class Tuple> void out(ostream &os, const Tuple &t) {}
template <int N, class Tuple, class H, class... Ts>
void out(ostream &os, const Tuple &t) {
if (N)
os << " ";
os << get<N>(t);
out<N + 1, Tuple, Ts...>(os, t);
}
template <class... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &t) {
os << "(";
out<0, tuple<Ts...>, Ts...>(os, t);
os << ")";
return os;
}
// Debug
#define DUMP(x) cout << #x << " = " << (x) << endl
struct edge {
int to, cost;
};
const LL LINF = 1LL << 60;
const int IINF = 1 << 30;
const LL MOD = 1e9 + 7;
template <typename Type, typename Operators> struct AlgStruct {
Type x;
template <typename... Args> AlgStruct(Args... args) : x(args...) {}
template <typename... Args> decltype(auto) operator[](Args... args) {
return x.operator[](args...);
}
AlgStruct &operator=(const AlgStruct &value) & = default;
template <typename... Args> static const AlgStruct idAdd(Args... args) {
return Operators::IdAdd(args...);
}
template <typename... Args> static const AlgStruct idMul(Args... args) {
return Operators::IdMul(args...);
}
const AlgStruct operator+() const { return *this; }
const AlgStruct operator-() const { return Operators::Opposite(x); }
const AlgStruct reciprocal() const { return Operators::Reciprocal(x); }
AlgStruct &operator+=(const AlgStruct &rhs) {
x = Operators::Add(x, rhs.x);
return *this;
}
AlgStruct &operator-=(const AlgStruct &rhs) {
*this += -rhs;
return *this;
}
AlgStruct &operator*=(const AlgStruct &rhs) {
x = Operators::Mul(x, rhs.x);
return *this;
}
AlgStruct &operator/=(const AlgStruct &rhs) {
return *this *= rhs.reciprocal();
}
const AlgStruct operator+(const AlgStruct &rhs) const {
return AlgStruct(*this) += rhs;
}
const AlgStruct operator-(const AlgStruct &rhs) const {
return AlgStruct(*this) -= rhs;
}
const AlgStruct operator*(const AlgStruct &rhs) const {
return AlgStruct(*this) *= rhs;
}
const AlgStruct operator/(const AlgStruct &rhs) const {
return AlgStruct(*this) /= rhs;
}
const AlgStruct power(long long n) const { return Operators::Power(x, n); }
bool operator<(const AlgStruct &rhs) const {
return Operators::Less(x, rhs.x);
}
bool operator>(const AlgStruct &rhs) const { return rhs < *this; }
bool operator<=(const AlgStruct &rhs) const { return !(*this > rhs); }
bool operator>=(const AlgStruct &rhs) const { return !(*this < rhs); }
bool operator==(const AlgStruct &rhs) const {
return !(*this < rhs) && !(*this > rhs);
}
bool operator!=(const AlgStruct &rhs) const { return !(*this == rhs); }
};
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator+(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) + rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator-(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) - rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator*(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) * rhs;
}
template <typename Type, typename Operators>
const AlgStruct<Type, Operators>
operator/(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) / rhs;
}
template <typename Type, typename Operators>
bool operator<(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) < rhs;
}
template <typename Type, typename Operators>
bool operator>(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) > rhs;
}
template <typename Type, typename Operators>
bool operator<=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) <= rhs;
}
template <typename Type, typename Operators>
bool operator>=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) >= rhs;
}
template <typename Type, typename Operators>
bool operator==(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) == rhs;
}
template <typename Type, typename Operators>
bool operator!=(const Type &lhs, const AlgStruct<Type, Operators> &rhs) {
return AlgStruct<Type, Operators>(lhs) != rhs;
}
template <typename Type, typename Operators>
auto &operator<<(ostream &s, const AlgStruct<Type, Operators> &value) {
s << value.x;
return s;
}
template <typename T, T mod> struct GaloisFieldOperators {
static T Add(T lhs, T rhs) { return (lhs + rhs) % mod; };
static T Mul(T lhs, T rhs) { return (lhs * rhs) % mod; };
static T IdAdd() { return 0; };
static T IdMul() { return 1; };
static T Opposite(T value) { return ((-value % mod) + mod) % mod; };
static bool Less(T lhs, T rhs) { return lhs < rhs; };
static T Power(T value, long long n) {
T res = IdMul();
while (n > 0) {
if (n & 1)
res = Mul(res, value);
value = Mul(value, value);
n >>= 1;
}
return res;
}
static T Reciprocal(T value) { return Power(value, mod - 2); }
};
using GaloisField = AlgStruct<long long, GaloisFieldOperators<long long, MOD>>;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
vector<int> s(N + 1);
for (int i = 0; i < N; ++i) {
s[i + 1] = s[i] ^ a[i];
}
if (s[N] != 0) {
int d = s[N];
vector<LL> p;
int cnt = 0;
for (int i = 0; i < N + 1; ++i) {
if (s[i] == d) {
p.push_back(cnt);
} else if (s[i] == 0) {
++cnt;
}
}
int D = p.size();
vector<GaloisField> dp(D + 1), sum0(D + 1), sum1(D + 1);
for (int i = 0; i < D; ++i) {
dp[i + 1] = 1LL - sum1[i] + p[i] * sum0[i];
sum0[i + 1] = sum0[i] + dp[i + 1];
sum1[i + 1] = sum1[i] + dp[i + 1] * p[i];
}
GaloisField ans = dp[D];
cout << ans << endl;
}
else {
const int dmax = 1 << 20;
vector<vector<LL>> p(dmax + 1);
int cnt = 0;
for (int i = 0; i < N + 1; ++i) {
if (s[i] == 0) {
++cnt;
} else {
p[s[i]].push_back(cnt);
}
}
GaloisField ans = GaloisField(2).power(cnt - 2);
for (int d = 1; d < dmax + 1; ++d) {
int D = p[d].size();
vector<GaloisField> dp(D + 1), sum0(D + 1), sum1(D + 1);
for (int i = 0; i < D; ++i) {
dp[i + 1] = 1LL - sum1[i] + p[d][i] * sum0[i];
sum0[i + 1] = sum0[i] + dp[i + 1];
sum1[i + 1] = sum1[i] + dp[i + 1] * p[d][i];
ans += dp[i + 1];
}
}
cout << ans << endl;
}
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 869,248 | 869,249 | u960524878 | cpp |
p03053 | #include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
const int INF = 100000000;
int main() {
typedef pair<int, int> P;
int H, W, i, j, n = 0;
scanf("%d%d", &H, &W);
queue<P> que;
char A[1000][1000];
int d[1000][1000];
for (i = 0; i < H; i++)
for (j = 0; j < W; j++) {
scanf(" %c", &A[i][j]);
d[i][j] = INF;
if (A[i][j] == '#') {
que.push(P(i, j)); //黒点をキューに入れる
d[i][j] = 0;
}
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans = 0;
while (que.size()) {
P p = que.front();
que.pop();
//移動4方向をループ
for (i = 0; i < 4; i++) {
//黒塗りにする点をnx,nyとする
int ny = p.first + dy[i], nx = p.second + dx[i];
//移動判定
if (0 <= nx && nx < W && 0 <= ny && ny < H && A[ny][nx] != '#' &&
d[ny][nx] == INF) {
que.push(P(nx, ny));
d[ny][nx] = d[p.second][p.first] + 1;
ans = max(ans, d[ny][nx]);
}
}
}
printf("%d", ans);
} | #include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
const int INF = 100000000;
int main() {
typedef pair<int, int> P;
int H, W, i, j, n = 0;
scanf("%d%d", &H, &W);
queue<P> que;
char A[1000][1000];
int d[1000][1000];
for (i = 0; i < H; i++)
for (j = 0; j < W; j++) {
scanf(" %c", &A[i][j]);
d[i][j] = INF;
if (A[i][j] == '#') {
que.push(P(i, j)); //黒点をキューに入れる
d[i][j] = 0;
}
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans = 0;
while (que.size()) {
P p = que.front();
que.pop();
//移動4方向をループ
for (i = 0; i < 4; i++) {
//黒塗りにする点をnx,nyとする
int ny = p.first + dy[i], nx = p.second + dx[i];
//移動判定
if (0 <= nx && nx < W && 0 <= ny && ny < H && A[ny][nx] != '#' &&
d[ny][nx] == INF) {
que.push(P(ny, nx));
d[ny][nx] = d[p.first][p.second] + 1;
ans = max(ans, d[ny][nx]);
}
}
}
printf("%d", ans);
} | [
"call.arguments.change",
"call.arguments.add",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 869,262 | 869,263 | u203033720 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
int H, W;
string s[1024];
int di[4] = {1, 0, -1, 0};
int dj[4] = {0, -1, 0, 1};
int main() {
cin >> H >> W;
for (int i = 1; i <= H; i++) {
cin >> s[i];
s[i] = "#" + s[i] + "#";
}
for (int j = 0; j < W + 2; j++) {
s[0] += '*';
s[H + 1] += '*';
}
queue<int> q;
for (int i = 0; i <= H; i++)
for (int j = 0; j <= W; j++) {
if (s[i][j] == '#') {
q.push(i);
q.push(j);
q.push(0);
}
}
int ans = 0;
while (!q.empty()) {
int ci = q.front();
q.pop();
int cj = q.front();
q.pop();
int ct = q.front();
q.pop();
ans = max(ans, ct);
for (int i = 0; i < 4; i++) {
int ni = ci + di[i];
int nj = cj + dj[i];
if (s[ni][nj] == '.') {
s[ni][nj] = '#';
q.push(ni);
q.push(nj);
q.push(ct + 1);
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int H, W;
string s[1024];
int di[4] = {1, 0, -1, 0};
int dj[4] = {0, -1, 0, 1};
int main() {
cin >> H >> W;
for (int i = 1; i <= H; i++) {
cin >> s[i];
s[i] = "*" + s[i] + "*";
}
for (int j = 0; j < W + 2; j++) {
s[0] += '*';
s[H + 1] += '*';
}
queue<int> q;
for (int i = 0; i <= H; i++)
for (int j = 0; j <= W; j++) {
if (s[i][j] == '#') {
q.push(i);
q.push(j);
q.push(0);
}
}
int ans = 0;
while (!q.empty()) {
int ci = q.front();
q.pop();
int cj = q.front();
q.pop();
int ct = q.front();
q.pop();
ans = max(ans, ct);
for (int i = 0; i < 4; i++) {
int ni = ci + di[i];
int nj = cj + dj[i];
if (s[ni][nj] == '.') {
s[ni][nj] = '#';
q.push(ni);
q.push(nj);
q.push(ct + 1);
}
}
}
cout << ans << endl;
return 0;
}
| [
"literal.string.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 869,264 | 869,265 | u628262476 | cpp |
p03053 | // Darker and Darker
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
struct Point {
int x;
int y;
int number;
};
int H, W;
int move(int met[1000][1000], Point p, queue<Point> &q, int x1, int y1,
int count) {
int x2 = x1 + p.x;
int y2 = y1 + p.y;
if (x2 >= W || y2 >= H || x2 < 0 || y2 < 0) {
return count;
}
if (met[y2][x2] > -1) {
return count;
}
int number = p.number + 1;
met[y2][x2] = number;
p.x = x2;
p.y = y2;
p.number = number;
q.push(p);
count = count < number ? number : count;
return count;
}
int main() {
int met[1000][1000];
cin >> H >> W;
int number = 0;
queue<Point> q;
// 初期化
for (int i = 0; i < H; i++) {
string s;
cin >> s;
for (int j = 0; j < W; j++) {
if (s[j] == '#') {
number++;
met[i][j] = 0;
Point p;
p.x = i;
p.y = j;
p.number = 0;
q.push(p);
} else {
met[i][j] = -1;
}
}
}
int count = 0;
while (!q.empty()) {
Point p = q.front();
q.pop();
// 隣接するセルをキューに追加する
count = move(met, p, q, 0, -1, count);
count = move(met, p, q, -1, 0, count);
count = move(met, p, q, 1, 0, count);
count = move(met, p, q, 0, 1, count);
}
cout << count << endl;
return 0;
} | // Darker and Darker
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
struct Point {
int x;
int y;
int number;
};
int H, W;
int move(int met[1000][1000], Point p, queue<Point> &q, int x1, int y1,
int count) {
int x2 = x1 + p.x;
int y2 = y1 + p.y;
if (x2 >= W || y2 >= H || x2 < 0 || y2 < 0) {
return count;
}
if (met[y2][x2] > -1) {
return count;
}
int number = p.number + 1;
met[y2][x2] = number;
p.x = x2;
p.y = y2;
p.number = number;
q.push(p);
count = count < number ? number : count;
return count;
}
int main() {
int met[1000][1000];
cin >> H >> W;
int number = 0;
queue<Point> q;
// 初期化
for (int i = 0; i < H; i++) {
string s;
cin >> s;
for (int j = 0; j < W; j++) {
if (s[j] == '#') {
number++;
met[i][j] = 0;
Point p;
p.x = j;
p.y = i;
p.number = 0;
q.push(p);
} else {
met[i][j] = -1;
}
}
}
int count = 0;
while (!q.empty()) {
Point p = q.front();
q.pop();
// 隣接するセルをキューに追加する
count = move(met, p, q, 0, -1, count);
count = move(met, p, q, -1, 0, count);
count = move(met, p, q, 1, 0, count);
count = move(met, p, q, 0, 1, count);
}
cout << count << endl;
return 0;
} | [
"assignment.value.change",
"identifier.change"
] | 869,268 | 869,269 | u362209280 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
char a[maxn][maxn];
int v[maxn][maxn];
int n, m;
int ans;
struct Node {
int x;
int y;
int d;
};
queue<Node> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", a[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j] == '#') {
v[i][j] = 1;
q.push((Node){i, j, 0});
}
while (!q.empty()) {
int x = q.front().x;
int y = q.front().y;
int d = q.front().d;
ans = d;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m)
continue;
if (v[xx][yy])
continue;
if (a[xx][yy] == '#')
continue;
v[xx][yy] = 1;
q.push((Node){xx, yy, d + 1});
}
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
char a[maxn][maxn];
int v[maxn][maxn];
int n, m;
int ans;
struct Node {
int x;
int y;
int d;
};
queue<Node> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", a[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == '#') {
v[i][j] = 1;
q.push((Node){i, j, 0});
}
while (!q.empty()) {
int x = q.front().x;
int y = q.front().y;
int d = q.front().d;
ans = d;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m)
continue;
if (v[xx][yy])
continue;
if (a[xx][yy] == '#')
continue;
v[xx][yy] = 1;
q.push((Node){xx, yy, d + 1});
}
}
printf("%d\n", ans);
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 869,274 | 869,275 | u174678554 | cpp |
p03053 | #include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < (n); i++)
#define FOR(i, a, b) for (long i = (a); i < (b); i++)
#define dump(x) cerr << #x << " => " << (x) << endl
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) \
vec.erase(unique(vec.begin(), vec.end()), vec.end()) //ソートの必要あり
#define IN(n, m) (!(m.find(n) == m.end()))
#define FINDL(vec, x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define FINDU(vec, x) (upper_bound(vec.begin(), vec.end(), x) - vec.begin())
#define EQ(a, b) (abs(a - b) < 1e-10)
using namespace std;
typedef long long LL;
constexpr int dx[4] = {0, 1, 0, -1};
constexpr int dy[4] = {1, 0, -1, 0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
// LONG_MAX,LLONG_MAX
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class Key, class Value>
ostream &operator<<(ostream &s, map<Key, Value> M) {
for (auto itr = begin(M); itr != end(M); ++itr) {
s << itr->first << ":" << itr->second;
}
return s;
}
struct Node {
long d, i, j;
};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
priority_queue<Node, vector<Node>, function<bool(Node, Node)>> que(
[](const Node &a, const Node &b) { return a.d > b.d; });
long H, W;
cin >> H >> W;
vector<string> A(H);
vector<vector<long>> used(H, vector<long>(W, -1));
REP(i, H) {
cin >> A[i];
REP(j, W) {
if (A[i][j] == '#') {
que.push(Node{0, i, j});
used[i][j] = 0;
}
}
}
while (!que.empty()) {
Node ret = que.top();
long d = ret.d;
long i = ret.i;
long j = ret.j;
que.pop();
if (i > 0 && used[i - 1][j] == -1) {
used[i - 1][j] = d + 1;
que.push(Node{d + 1, i - 1, j});
}
if (i < H - 1 && used[i + 1][j] == -1) {
used[i + 1][j] = d + 1;
que.push(Node{d + 1, i + 1, j});
}
if (j > 0 && used[i][j - 1] == -1) {
used[i][j - 1] = d + 1;
que.push(Node{d + 1, i, j - 1});
}
if (j < W - 1 && used[i][j + 1] == -1) {
used[i][j + 1] = d + 1;
que.push(Node{d + 1, i, j + 1});
}
}
long ans = 0;
REP(i, H) {
REP(j, H) { ans = max(ans, used[i][j]); }
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < (n); i++)
#define FOR(i, a, b) for (long i = (a); i < (b); i++)
#define dump(x) cerr << #x << " => " << (x) << endl
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) \
vec.erase(unique(vec.begin(), vec.end()), vec.end()) //ソートの必要あり
#define IN(n, m) (!(m.find(n) == m.end()))
#define FINDL(vec, x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define FINDU(vec, x) (upper_bound(vec.begin(), vec.end(), x) - vec.begin())
#define EQ(a, b) (abs(a - b) < 1e-10)
using namespace std;
typedef long long LL;
constexpr int dx[4] = {0, 1, 0, -1};
constexpr int dy[4] = {1, 0, -1, 0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
// LONG_MAX,LLONG_MAX
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class Key, class Value>
ostream &operator<<(ostream &s, map<Key, Value> M) {
for (auto itr = begin(M); itr != end(M); ++itr) {
s << itr->first << ":" << itr->second;
}
return s;
}
struct Node {
long d, i, j;
};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
priority_queue<Node, vector<Node>, function<bool(Node, Node)>> que(
[](const Node &a, const Node &b) { return a.d > b.d; });
long H, W;
cin >> H >> W;
vector<string> A(H);
vector<vector<long>> used(H, vector<long>(W, -1));
REP(i, H) {
cin >> A[i];
REP(j, W) {
if (A[i][j] == '#') {
que.push(Node{0, i, j});
used[i][j] = 0;
}
}
}
while (!que.empty()) {
Node ret = que.top();
long d = ret.d;
long i = ret.i;
long j = ret.j;
que.pop();
if (i > 0 && used[i - 1][j] == -1) {
used[i - 1][j] = d + 1;
que.push(Node{d + 1, i - 1, j});
}
if (i < H - 1 && used[i + 1][j] == -1) {
used[i + 1][j] = d + 1;
que.push(Node{d + 1, i + 1, j});
}
if (j > 0 && used[i][j - 1] == -1) {
used[i][j - 1] = d + 1;
que.push(Node{d + 1, i, j - 1});
}
if (j < W - 1 && used[i][j + 1] == -1) {
used[i][j + 1] = d + 1;
que.push(Node{d + 1, i, j + 1});
}
}
long ans = 0;
REP(i, H) {
REP(j, W) { ans = max(ans, used[i][j]); }
}
cout << ans << endl;
}
| [] | 869,290 | 869,291 | u925364229 | cpp |
p03053 | #include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define ms(v, x) memset(v, x, sizeof(v))
#define pii pair<int, int>
#define ff first
#define ss second
#define frr(i, n) for (int i = 0; i < n; i++)
#define td(v) v.begin(), v.end()
#define inf 1000000000 // 1e9
#define M 1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m) {
int ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int exp(int a, int b, int m) {
if (b == 0)
return 1;
if (b == 1)
return mod(a, m);
int k = mod(exp(a, b / 2, m), m);
if (b & 1) {
return mod(a * mod(k * k, m), m);
} else
return mod(k * k, m);
}
char t[1010][1010];
struct node {
int x, y, lvl;
node(int x, int y) {
this->x = x;
this->y = y;
this->lvl = 0;
}
};
int n, m;
bool ok(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < n); }
int32_t main() {
cin >> n >> m;
queue<node> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> t[i][j];
if (t[i][j] == '#') {
q.push(node(i, j));
}
}
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
while (!q.empty()) {
node now = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nx = now.x + dx[i];
int ny = now.y + dy[i];
if (ok(nx, ny) && t[nx][ny] != '#') {
node nxt = node(nx, ny);
nxt.lvl = now.lvl + 1;
q.push(nxt);
t[nx][ny] = '#';
}
}
if (q.empty()) {
cout << now.lvl << endl;
}
}
} | #include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define ms(v, x) memset(v, x, sizeof(v))
#define pii pair<int, int>
#define ff first
#define ss second
#define frr(i, n) for (int i = 0; i < n; i++)
#define td(v) v.begin(), v.end()
#define inf 1000000000 // 1e9
#define M 1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m) {
int ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int exp(int a, int b, int m) {
if (b == 0)
return 1;
if (b == 1)
return mod(a, m);
int k = mod(exp(a, b / 2, m), m);
if (b & 1) {
return mod(a * mod(k * k, m), m);
} else
return mod(k * k, m);
}
char t[1010][1010];
struct node {
int x, y, lvl;
node(int x, int y) {
this->x = x;
this->y = y;
this->lvl = 0;
}
};
int n, m;
bool ok(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < m); }
int32_t main() {
cin >> n >> m;
queue<node> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> t[i][j];
if (t[i][j] == '#') {
q.push(node(i, j));
}
}
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
while (!q.empty()) {
node now = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nx = now.x + dx[i];
int ny = now.y + dy[i];
if (ok(nx, ny) && t[nx][ny] != '#') {
node nxt = node(nx, ny);
nxt.lvl = now.lvl + 1;
q.push(nxt);
t[nx][ny] = '#';
}
}
if (q.empty()) {
cout << now.lvl << endl;
}
}
} | [
"identifier.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 869,294 | 869,295 | u179760090 | cpp |
p03053 | #include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int score[1010][1010];
queue<pair<int, int>> que;
int h, w;
void bfs() {
while (que.empty() != true) {
pair<int, int> temp = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if (nx <= 0 || h + 1 <= nx || ny <= 0 || w + 1 <= ny)
continue;
else if (score[ny][nx] != -1)
continue;
else {
score[ny][nx] = score[temp.first][temp.second] + 1;
que.push(make_pair(ny, nx));
}
}
}
}
int main() {
cin >> h >> w;
memset(score, -1, sizeof(score));
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++) {
char temp;
cin >> temp;
if (temp == '#') {
score[i][j] = 0;
que.push(make_pair(i, j));
}
}
bfs();
int ans = -1;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
ans = max(ans, score[i][j]);
// cout << score[i][j] << " ";
}
// cout << endl;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int score[1010][1010];
queue<pair<int, int>> que;
int h, w;
void bfs() {
while (que.empty() != true) {
pair<int, int> temp = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if (nx <= 0 || w + 1 <= nx || ny <= 0 || h + 1 <= ny)
continue;
else if (score[ny][nx] != -1)
continue;
else {
score[ny][nx] = score[temp.first][temp.second] + 1;
que.push(make_pair(ny, nx));
}
}
}
}
int main() {
cin >> h >> w;
memset(score, -1, sizeof(score));
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++) {
char temp;
cin >> temp;
if (temp == '#') {
score[i][j] = 0;
que.push(make_pair(i, j));
}
}
bfs();
int ans = -1;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
ans = max(ans, score[i][j]);
// cout << score[i][j] << " ";
}
// cout << endl;
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,306 | 869,307 | u271153916 | cpp |
p03053 | #include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int score[1001][1001];
queue<pair<int, int>> que;
int h, w;
void bfs() {
while (que.empty() != true) {
pair<int, int> temp = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if (nx <= 0 || h + 1 <= nx || ny <= 0 || w + 1 <= ny)
continue;
else if (score[ny][nx] != -1)
continue;
else {
score[ny][nx] = score[temp.first][temp.second] + 1;
que.push(make_pair(ny, nx));
}
}
}
}
int main() {
cin >> h >> w;
memset(score, -1, sizeof(score));
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++) {
char temp;
cin >> temp;
if (temp == '#') {
score[i][j] = 0;
que.push(make_pair(i, j));
}
}
bfs();
int ans = -1;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
ans = max(ans, score[i][j]);
// cout << score[i][j] << " ";
}
// cout << endl;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int score[1010][1010];
queue<pair<int, int>> que;
int h, w;
void bfs() {
while (que.empty() != true) {
pair<int, int> temp = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if (nx <= 0 || w + 1 <= nx || ny <= 0 || h + 1 <= ny)
continue;
else if (score[ny][nx] != -1)
continue;
else {
score[ny][nx] = score[temp.first][temp.second] + 1;
que.push(make_pair(ny, nx));
}
}
}
}
int main() {
cin >> h >> w;
memset(score, -1, sizeof(score));
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++) {
char temp;
cin >> temp;
if (temp == '#') {
score[i][j] = 0;
que.push(make_pair(i, j));
}
}
bfs();
int ans = -1;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
ans = max(ans, score[i][j]);
// cout << score[i][j] << " ";
}
// cout << endl;
}
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,308 | 869,307 | u271153916 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>
int main() {
queue<P> que;
int H, W;
long long INF = 1000000000, x, y;
cin >> H >> W;
char a[H][W];
int S[H][W], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a[i][j];
S[i][j] = INF;
if (a[i][j] == '#') {
S[i][j] = 0;
que.push({i, j});
}
}
}
while (!que.empty()) {
P p = que.front();
que.pop();
x = p.first;
y = p.second;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= W || ny < 0 || ny >= H)
continue;
if (S[nx][ny] == INF) {
S[nx][ny] = S[x][y] + 1;
que.push({nx, ny});
}
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, S[i][j]);
}
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>
int main() {
queue<P> que;
int H, W;
long long INF = 1000000000, x, y;
cin >> H >> W;
char a[H][W];
int S[H][W], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> a[i][j];
S[i][j] = INF;
if (a[i][j] == '#') {
S[i][j] = 0;
que.push({i, j});
}
}
}
while (!que.empty()) {
P p = que.front();
que.pop();
x = p.first;
y = p.second;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (S[nx][ny] == INF) {
S[nx][ny] = S[x][y] + 1;
que.push({nx, ny});
}
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = max(ans, S[i][j]);
}
}
cout << ans;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,313 | 869,314 | u441250130 | cpp |
p03053 | #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int H, W;
vector<string> A;
vector<vector<int>> d;
cin >> H >> W;
for (int i = 0; i < H; i++) {
string tmp;
cin >> tmp;
A.push_back(tmp);
}
for (int i = 0; i < H; i++)
d.push_back(vector<int>(W, -1));
queue<pair<int, int>> q;
for (int i = 0; i < H; i++)
for (int j = 0; j < H; j++)
if (A[i][j] == '#') {
q.push(make_pair(i, j));
d[i][j] = 0;
}
while (!q.empty()) {
auto x = q.front();
q.pop();
int i = x.first;
int j = x.second;
int c = d[i][j];
if (i + 1 >= 0 && i + 1 < H && j >= 0 && j < W && d[i + 1][j] == -1) {
q.push(make_pair(i + 1, j));
d[i + 1][j] = c + 1;
}
if (i >= 0 && i < H && j + 1 >= 0 && j + 1 < W && d[i][j + 1] == -1) {
q.push(make_pair(i, j + 1));
d[i][j + 1] = c + 1;
}
if (i - 1 >= 0 && i - 1 < H && j >= 0 && j < W && d[i - 1][j] == -1) {
q.push(make_pair(i - 1, j));
d[i - 1][j] = c + 1;
}
if (i >= 0 && i < H && j - 1 >= 0 && j - 1 < W && d[i][j - 1] == -1) {
q.push(make_pair(i, j - 1));
d[i][j - 1] = c + 1;
}
}
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < H; j++)
ans = max(ans, d[i][j]);
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int H, W;
vector<string> A;
vector<vector<int>> d;
cin >> H >> W;
for (int i = 0; i < H; i++) {
string tmp;
cin >> tmp;
A.push_back(tmp);
}
for (int i = 0; i < H; i++)
d.push_back(vector<int>(W, -1));
queue<pair<int, int>> q;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (A[i][j] == '#') {
q.push(make_pair(i, j));
d[i][j] = 0;
}
while (!q.empty()) {
auto x = q.front();
q.pop();
int i = x.first;
int j = x.second;
int c = d[i][j];
if (i + 1 >= 0 && i + 1 < H && j >= 0 && j < W && d[i + 1][j] == -1) {
q.push(make_pair(i + 1, j));
d[i + 1][j] = c + 1;
}
if (i >= 0 && i < H && j + 1 >= 0 && j + 1 < W && d[i][j + 1] == -1) {
q.push(make_pair(i, j + 1));
d[i][j + 1] = c + 1;
}
if (i - 1 >= 0 && i - 1 < H && j >= 0 && j < W && d[i - 1][j] == -1) {
q.push(make_pair(i - 1, j));
d[i - 1][j] = c + 1;
}
if (i >= 0 && i < H && j - 1 >= 0 && j - 1 < W && d[i][j - 1] == -1) {
q.push(make_pair(i, j - 1));
d[i][j - 1] = c + 1;
}
}
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
ans = max(ans, d[i][j]);
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 869,317 | 869,318 | u090436701 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
namespace io {
const int l = 1 << 19;
char *s, *t, buf[l], c;
char gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
return s == t ? EOF : *s++;
}
return *s++;
}
template <class IT> void gi(IT &x) {
x = 0;
c = gc();
while (c < '0' || c > '9')
c = gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = gc();
}
}
} // namespace io
using io::gc;
using io::gi;
template <class IT> void chkmin(IT &a, IT b) {
if (b < a)
a = b;
}
template <class IT> void chkmax(IT &a, IT b) {
if (a < b)
a = b;
}
const int N = 1005;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m, vis[N][N], s, x, y;
char c[N][N];
struct node {
int x, y, d;
};
queue<node> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", c[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (c[i][j] == '#') {
vis[i][j] = 1;
q.push((node){i, j, 0});
}
while (!q.empty()) {
x = q.front().x;
y = q.front().y;
s = q.front().d;
q.pop();
for (int i = 0; i < 4; i++) {
int X = x + dx[i], Y = y + dy[i];
if (X && X <= n && Y && Y <= n && !vis[X][Y]) {
vis[X][Y] = 1;
q.push((node){X, Y, s + 1});
}
}
}
printf("%d", s);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
namespace io {
const int l = 1 << 19;
char *s, *t, buf[l], c;
char gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
return s == t ? EOF : *s++;
}
return *s++;
}
template <class IT> void gi(IT &x) {
x = 0;
c = gc();
while (c < '0' || c > '9')
c = gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = gc();
}
}
} // namespace io
using io::gc;
using io::gi;
template <class IT> void chkmin(IT &a, IT b) {
if (b < a)
a = b;
}
template <class IT> void chkmax(IT &a, IT b) {
if (a < b)
a = b;
}
const int N = 1005;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m, vis[N][N], s, x, y;
char c[N][N];
struct node {
int x, y, d;
};
queue<node> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", c[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (c[i][j] == '#') {
vis[i][j] = 1;
q.push((node){i, j, 0});
}
while (!q.empty()) {
x = q.front().x;
y = q.front().y;
s = q.front().d;
q.pop();
for (int i = 0; i < 4; i++) {
int X = x + dx[i], Y = y + dy[i];
if (X && X <= n && Y && Y <= m && !vis[X][Y]) {
vis[X][Y] = 1;
q.push((node){X, Y, s + 1});
}
}
}
printf("%d", s);
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,319 | 869,320 | u108493359 | cpp |
p03053 | #include <array>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
int main() {
/*
int W, H;
cin >> W >> H;
vector<array<int, 1000>> arr(H);
int MAX = 0;
for(int y = 0; y < H; y++){
for(int x = 0; x < W; x++){
char buf;
cin >> buf;
if(buf == '#'){
arr[y][x] = 0;
continue;
}
arr[y][x] = 1;
if(y == 0){
arr[y][x] = 1;
MAX = max(MAX, 1);
continue;
}
int Tg = arr[y-1][x];
if(x != 0){
Tg = min(Tg, arr[y-1][x-1]);
}
if(x < W-1){
Tg = min(Tg, arr[y-1][x+1]);
}
if(y-2*Tg < 0){
arr[y][x] = Tg + 1;
MAX = max(MAX, arr[y][x]);
}
else if(arr[y-2*Tg][x] != 0){
arr[y][x] = Tg + 1;
MAX = max(MAX, arr[y][x]);
}
else
arr[y][x] = Tg;
}
}
cout << MAX << endl;
*/
int W, H;
cin >> W >> H;
char buf;
queue<pair<int, int>> que;
vector<array<int, 1000>> arr(H);
int MAX = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
cin >> buf;
if (buf == '#') {
arr[y][x] = 0;
que.push(make_pair(y, x));
} else {
arr[y][x] = 1000000000;
}
}
}
while (!que.empty()) {
auto Tg = que.front();
que.pop();
if (Tg.first > 0) {
if (arr[Tg.first - 1][Tg.second] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first - 1][Tg.second] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first - 1, Tg.second));
}
}
if (Tg.first < H - 1) {
if (arr[Tg.first + 1][Tg.second] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first + 1][Tg.second] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first + 1, Tg.second));
}
}
if (Tg.second > 0) {
if (arr[Tg.first][Tg.second - 1] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first][Tg.second - 1] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first, Tg.second - 1));
}
}
if (Tg.first < W - 1) {
if (arr[Tg.first][Tg.second + 1] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first][Tg.second + 1] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first, Tg.second + 1));
}
}
MAX = max(MAX, arr[Tg.first][Tg.second]);
}
cout << MAX << endl;
return 0;
} | #include <array>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
int main() {
int W, H;
cin >> H >> W;
char buf;
queue<pair<int, int>> que;
vector<array<int, 1000>> arr(H);
int MAX = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
cin >> buf;
if (buf == '#') {
arr[y][x] = 0;
que.push(make_pair(y, x));
} else {
arr[y][x] = 1000000000;
}
}
}
while (!que.empty()) {
auto Tg = que.front();
que.pop();
if (Tg.first > 0) {
if (arr[Tg.first - 1][Tg.second] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first - 1][Tg.second] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first - 1, Tg.second));
}
}
if (Tg.first < H - 1) {
if (arr[Tg.first + 1][Tg.second] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first + 1][Tg.second] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first + 1, Tg.second));
}
}
if (Tg.second > 0) {
if (arr[Tg.first][Tg.second - 1] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first][Tg.second - 1] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first, Tg.second - 1));
}
}
if (Tg.second < W - 1) {
if (arr[Tg.first][Tg.second + 1] > arr[Tg.first][Tg.second] + 1) {
arr[Tg.first][Tg.second + 1] = arr[Tg.first][Tg.second] + 1;
que.push(make_pair(Tg.first, Tg.second + 1));
}
}
MAX = max(MAX, arr[Tg.first][Tg.second]);
}
cout << MAX << endl;
return 0;
} | [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 869,325 | 869,324 | u331948661 | cpp |
p03053 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
#define INF 1LL << 60
#define MOD 1000000007;
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) \
cout << #a << ": " << endl; \
for (const auto &v : (a)) \
cout << v << endl
int H, W;
vector<string> in;
int d[1005][1005];
int main() {
cin.tie(0);
cin >> H >> W;
in.resize(H, "");
REP(i, H) cin >> in[i];
queue<pi> q;
REP(i, H) REP(j, W) {
d[i][j] = -1;
if (in[i][j] == '#') {
d[i][j] = 0;
q.push(pi(i, j));
}
}
int x, y, nx, ny;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
while (q.size()) {
pi p = q.front();
q.pop();
x = p.first;
y = p.second;
REP(i, 4) {
nx = x + dx[i];
ny = y + dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (d[nx][ny] == -1) {
d[nx][ny] = d[x][y] + 1;
q.push(pi(nx, ny));
}
}
}
int ans = -1;
REP(i, W) REP(j, H) ans = max(ans, d[i][j]);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
#define INF 1LL << 60
#define MOD 1000000007;
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) \
cout << #a << ": " << endl; \
for (const auto &v : (a)) \
cout << v << endl
int H, W;
vector<string> in;
int d[1005][1005];
int main() {
cin.tie(0);
cin >> H >> W;
in.resize(H, "");
REP(i, H) cin >> in[i];
queue<pi> q;
REP(i, H) REP(j, W) {
d[i][j] = -1;
if (in[i][j] == '#') {
d[i][j] = 0;
q.push(pi(i, j));
}
}
int x, y, nx, ny;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
while (q.size()) {
pi p = q.front();
q.pop();
x = p.first;
y = p.second;
REP(i, 4) {
nx = x + dx[i];
ny = y + dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (d[nx][ny] == -1) {
d[nx][ny] = d[x][y] + 1;
q.push(pi(nx, ny));
}
}
}
int ans = -1;
REP(i, H) REP(j, W) ans = max(ans, d[i][j]);
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"call.arguments.change",
"assignment.variable.change"
] | 869,336 | 869,337 | u703272444 | cpp |
p03053 | //
// main.cpp
// Atcoder
//
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
int H, W;
const int maxn = 1000 + 10;
char A[maxn][maxn];
struct Node {
int i, j, level;
};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool check(int x, int y) { return x > 0 && x <= H && y > 0 && y <= W; }
int bfs() {
int ans = 0;
queue<Node> q;
for (int i = 1; i <= H; i++) {
for (int j = 0; j <= W; j++) {
if (A[i][j] == '#') {
q.push(Node{i, j, 0});
}
}
}
while (!q.empty()) {
Node cur = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int x = cur.i + dx[i], y = cur.j + dy[i];
if (check(x, y) && A[x][y] == '.') {
A[x][y] = '#';
q.push(Node{x, y, cur.level + 1});
ans = max(ans, cur.level + 1);
}
}
}
return ans;
}
int main(int argc, const char *argv[]) {
scanf("%d%d", &H, &W);
for (int i = 0; i < H; i++) {
scanf("%s", A[i] + 1);
}
int ans = bfs();
printf("%d\n", ans);
return 0;
}
| //
// main.cpp
// Atcoder
//
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
int H, W;
const int maxn = 1000 + 10;
char A[maxn][maxn];
struct Node {
int i, j, level;
};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool check(int x, int y) { return x > 0 && x <= H && y > 0 && y <= W; }
int bfs() {
int ans = 0;
queue<Node> q;
for (int i = 1; i <= H; i++) {
for (int j = 0; j <= W; j++) {
if (A[i][j] == '#') {
q.push(Node{i, j, 0});
}
}
}
while (!q.empty()) {
Node cur = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int x = cur.i + dx[i], y = cur.j + dy[i];
if (check(x, y) && A[x][y] == '.') {
A[x][y] = '#';
q.push(Node{x, y, cur.level + 1});
ans = max(ans, cur.level + 1);
}
}
}
return ans;
}
int main(int argc, const char *argv[]) {
scanf("%d%d", &H, &W);
for (int i = 1; i <= H; i++) {
scanf("%s", A[i] + 1);
}
int ans = bfs();
printf("%d\n", ans);
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 869,372 | 869,373 | u797983470 | cpp |
p03053 | #include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) \
{ \
if (a < b) \
a = b; \
}
#define chmin(a, b) \
{ \
if (a > b) \
a = b; \
}
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll H, W;
string s[1111];
ll d[1111][1111];
ll dx[] = {0, -1, 0, 1};
ll dy[] = {-1, 0, 1, 0};
void bfs() {
ll i, j;
memset(d, -1, sizeof(d));
priority_queue<pair<ll, P>> q;
for (i = 0; i < H; i++) {
for (j = 0; j < W; j++) {
if (s[i][j] == '#') {
d[i][j] = 0;
q.push({0, {i, j}});
}
}
}
while (q.size()) {
pair<ll, P> f = q.top();
q.pop();
for (i = 0; i < 4; i++) {
ll tx = f.sc.ft + dx[i];
ll ty = f.sc.sc + dy[i];
if (tx < 0 || ty < 0 || tx >= H || ty >= W)
continue;
if (d[tx][ty] != -1)
continue;
d[tx][ty] = d[f.sc.ft][f.sc.sc] + 1;
q.push({-d[tx][ty], {tx, ty}});
}
}
}
int main(void) {
cin >> H >> W;
ll i, j;
for (i = 0; i < H; i++)
cin >> s[i];
bfs();
ll ans = INF;
for (i = 0; i < H; i++) {
for (j = 0; j < W; j++) {
chmax(ans, d[i][j]);
}
}
pt(ans);
}
| #include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) \
{ \
if (a < b) \
a = b; \
}
#define chmin(a, b) \
{ \
if (a > b) \
a = b; \
}
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll H, W;
string s[1111];
ll d[1111][1111];
ll dx[] = {0, -1, 0, 1};
ll dy[] = {-1, 0, 1, 0};
void bfs() {
ll i, j;
memset(d, -1, sizeof(d));
priority_queue<pair<ll, P>> q;
for (i = 0; i < H; i++) {
for (j = 0; j < W; j++) {
if (s[i][j] == '#') {
d[i][j] = 0;
q.push({0, {i, j}});
}
}
}
while (q.size()) {
pair<ll, P> f = q.top();
q.pop();
for (i = 0; i < 4; i++) {
ll tx = f.sc.ft + dx[i];
ll ty = f.sc.sc + dy[i];
if (tx < 0 || ty < 0 || tx >= H || ty >= W)
continue;
if (d[tx][ty] != -1)
continue;
d[tx][ty] = d[f.sc.ft][f.sc.sc] + 1;
q.push({-d[tx][ty], {tx, ty}});
}
}
}
int main(void) {
cin >> H >> W;
ll i, j;
for (i = 0; i < H; i++)
cin >> s[i];
bfs();
ll ans = 0;
for (i = 0; i < H; i++) {
for (j = 0; j < W; j++) {
chmax(ans, d[i][j]);
}
}
pt(ans);
}
| [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 869,374 | 869,375 | u768152935 | cpp |
p03053 | #define _USE_MATH_DEFINES
#include <bits/stdc++.h> //////////////////////////////////////////
#define deb(...) /////////////////////////////////////////////////
#define DBP(...) /////////////////////////////////////////////////
#ifdef LOC ///////////////////////////////////////////////////////
#include "debuglib.h" /////////////////////////////////////////////
#endif ///////////////////////////////////////////////////////////
#define x first //////////////////////////////////////////////////
#define y second /////////////////////////////////////////////////
#define pb push_back /////////////////////////////////////////////
#define sz(x) int((x).size()) /////////////////////////////////////
#define each(a, x) for (auto &a : (x)) /////////////////////////////////
#define all(x) (x).begin(), (x).end() //////////////////////////////
#define rep(i, b, e) for (int i = (b); i < (e); i++) ///////////////////////
using namespace std;
using ll = long long;
using Pii = pair<int, int>; //
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio ///
(0);
cin.tie(0);
cout << fixed << setprecision(18);
run();
return 0;
} ////
//-------------------------------------------------------------//
void run() {
int h, w;
cin >> h >> w;
vector<string> board(h);
each(r, board) cin >> r;
vector<Vi> dist(h, Vi(w, -1));
queue<Pii> que;
int ans = 0;
rep(i, 0, h) rep(j, 0, w) {
if (board[i][j] == '#') {
que.push({i, j});
dist[i][j] = 0;
}
}
auto relax = [&](int i, int j, int d) {
if (dist[i][j] == -1) {
dist[i][j] = d;
que.push({i, j});
ans = max(ans, d);
}
};
while (!que.empty()) {
Pii v = que.front();
int d = dist[v.x][v.y] + 1;
que.pop();
if (v.x > 0)
relax(v.x - 1, v.y, d);
if (v.y > 0)
relax(v.x, v.y - 1, d);
if (v.x + 1 < h)
relax(v.x + 1, v.y, d);
if (v.y + 1 < h)
relax(v.x, v.y + 1, d);
}
cout << ans << '\n';
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h> //////////////////////////////////////////
#define deb(...) /////////////////////////////////////////////////
#define DBP(...) /////////////////////////////////////////////////
#ifdef LOC ///////////////////////////////////////////////////////
#include "debuglib.h" /////////////////////////////////////////////
#endif ///////////////////////////////////////////////////////////
#define x first //////////////////////////////////////////////////
#define y second /////////////////////////////////////////////////
#define pb push_back /////////////////////////////////////////////
#define sz(x) int((x).size()) /////////////////////////////////////
#define each(a, x) for (auto &a : (x)) /////////////////////////////////
#define all(x) (x).begin(), (x).end() //////////////////////////////
#define rep(i, b, e) for (int i = (b); i < (e); i++) ///////////////////////
using namespace std;
using ll = long long;
using Pii = pair<int, int>; //
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio ///
(0);
cin.tie(0);
cout << fixed << setprecision(18);
run();
return 0;
} ////
//-------------------------------------------------------------//
void run() {
int h, w;
cin >> h >> w;
vector<string> board(h);
each(r, board) cin >> r;
vector<Vi> dist(h, Vi(w, -1));
queue<Pii> que;
int ans = 0;
rep(i, 0, h) rep(j, 0, w) {
if (board[i][j] == '#') {
que.push({i, j});
dist[i][j] = 0;
}
}
auto relax = [&](int i, int j, int d) {
if (dist[i][j] == -1) {
dist[i][j] = d;
que.push({i, j});
ans = max(ans, d);
}
};
while (!que.empty()) {
Pii v = que.front();
int d = dist[v.x][v.y] + 1;
que.pop();
if (v.x > 0)
relax(v.x - 1, v.y, d);
if (v.y > 0)
relax(v.x, v.y - 1, d);
if (v.x + 1 < h)
relax(v.x + 1, v.y, d);
if (v.y + 1 < w)
relax(v.x, v.y + 1, d);
}
cout << ans << '\n';
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,503 | 869,504 | u018915813 | cpp |
p03054 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100 // 000000000
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, P>
#define T tuple<int, int, int> // tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
int l, r;
l = 1;
r = h;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'D')
l = max(l - 1, 1);
if (t[i] == 'U')
r = min(r + 1, w);
if (s[i] == 'D')
r--;
if (s[i] == 'U')
l++;
}
if (l > sr || sr > r) {
cout << "NO" << endl;
return 0;
}
l = 1;
r = w;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'R')
l = max(l - 1, 1);
if (t[i] == 'L')
r = min(r + 1, h);
if (s[i] == 'R')
r--;
if (s[i] == 'L')
l++;
}
if (l > sc || sc > r) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100 // 000000000
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, P>
#define T tuple<int, int, int> // tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
int l, r;
l = 1;
r = h;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'D')
l = max(l - 1, 1);
if (t[i] == 'U')
r = min(r + 1, h);
if (s[i] == 'D')
r--;
if (s[i] == 'U')
l++;
}
if (l > sr || sr > r) {
cout << "NO" << endl;
return 0;
}
l = 1;
r = w;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'R')
l = max(l - 1, 1);
if (t[i] == 'L')
r = min(r + 1, w);
if (s[i] == 'R')
r--;
if (s[i] == 'L')
l++;
}
if (l > sc || sc > r) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 869,513 | 869,514 | u437779154 | cpp |
p03054 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100 // 000000000
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, P>
#define T tuple<int, int, int> // tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
int l, r;
l = 1;
r = h;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'D')
l = max(l - 1, 1);
if (t[i] == 'U')
r = min(r + 1, w);
if (s[i] == 'D')
r--;
if (s[i] == 'U')
l++;
}
if (l > sr || sr > r) {
cout << "NO" << endl;
return 0;
}
l = 1;
r = w;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'R')
max(l - 1, 1);
if (t[i] == 'L')
min(r + 1, h);
if (s[i] == 'R')
r--;
if (s[i] == 'L')
l++;
}
if (l > sc || sc > r) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100 // 000000000
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, P>
#define T tuple<int, int, int> // tuple<ll,ll,ll>
#define pr(x) cout << x << endl;
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
int l, r;
l = 1;
r = h;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'D')
l = max(l - 1, 1);
if (t[i] == 'U')
r = min(r + 1, h);
if (s[i] == 'D')
r--;
if (s[i] == 'U')
l++;
}
if (l > sr || sr > r) {
cout << "NO" << endl;
return 0;
}
l = 1;
r = w;
for (int i = n - 1; i >= 0; i--) {
if (l > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'R')
l = max(l - 1, 1);
if (t[i] == 'L')
r = min(r + 1, w);
if (s[i] == 'R')
r--;
if (s[i] == 'L')
l++;
}
if (l > sc || sc > r) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"assignment.change"
] | 869,515 | 869,514 | u437779154 | cpp |
p03054 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod = 998244353 ;
const ll mod = 1000000007;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n - 1; i >= 0; --i)
#define REP_FROM_REV(i, j, n) for (ll i = n - 1; i >= j; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ll(x.size())
template <typename T> inline T chmax(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T chmin(T &a, const T b) {
return a = (a > b) ? b : a;
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
using Pair = pair<ll, ll>;
template <ll Modulus> struct ModInt {
ll a;
constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {}
constexpr ll &value() noexcept { return a; }
constexpr const ll &value() const noexcept { return a; }
constexpr ModInt operator+(const ModInt x) const noexcept {
return ModInt(*this) += x;
}
constexpr ModInt operator-(const ModInt x) const noexcept {
return ModInt(*this) -= x;
}
constexpr ModInt operator*(const ModInt x) const noexcept {
return ModInt(*this) *= x;
}
constexpr ModInt operator/(const ModInt x) const noexcept {
return ModInt(*this) /= x;
}
constexpr ModInt &operator+=(const ModInt x) noexcept {
a += x.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt x) noexcept {
if (a < x.a) {
a += Modulus;
}
a -= x.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt x) noexcept {
a = a * x.a % Modulus;
return *this;
}
constexpr ModInt &operator/=(ModInt x) noexcept {
ll exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= x;
}
x *= x;
exp /= 2;
}
return *this;
}
constexpr ModInt operator-() noexcept { return ModInt(-a); }
friend ostream &operator<<(ostream &os, const ModInt &m) {
os << m.a;
return os;
}
};
using mint = ModInt<mod>;
bool check(ll h, ll r, const vector<ll> &a) {
ll lft = -1;
ll rgt = h;
REP_REV(i, sz(a)) {
if (i % 2 == 0) {
if (a[i] == 1) {
rgt--;
} else if (a[i] == -1) {
lft++;
}
} else {
if (a[i] == 1) {
lft--;
} else if (a[i] == -1) {
rgt++;
}
}
if (rgt - lft)
return true;
if (lft < 0)
lft = -1;
if (rgt > h)
rgt = h;
}
return r <= lft || rgt <= r;
}
signed main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll h, w, n, r, c;
string s, t;
cin >> h >> w >> n >> r >> c >> s >> t;
vector<ll> x(2 * n), y(2 * n);
REP(i, n) {
if (s[i] == 'L') {
x[2 * i] = -1;
} else if (s[i] == 'R') {
x[2 * i] = 1;
} else if (s[i] == 'U') {
y[2 * i] = -1;
} else {
y[2 * i] = 1;
}
if (t[i] == 'L') {
x[2 * i + 1] = -1;
} else if (t[i] == 'R') {
x[2 * i + 1] = 1;
} else if (t[i] == 'U') {
y[2 * i + 1] = -1;
} else {
y[2 * i + 1] = 1;
}
}
if (check(h, r - 1, y)) {
cout << "NO" << endl;
} else if (check(w, c - 1, x)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod = 998244353 ;
const ll mod = 1000000007;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n - 1; i >= 0; --i)
#define REP_FROM_REV(i, j, n) for (ll i = n - 1; i >= j; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ll(x.size())
template <typename T> inline T chmax(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T chmin(T &a, const T b) {
return a = (a > b) ? b : a;
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
using Pair = pair<ll, ll>;
template <ll Modulus> struct ModInt {
ll a;
constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {}
constexpr ll &value() noexcept { return a; }
constexpr const ll &value() const noexcept { return a; }
constexpr ModInt operator+(const ModInt x) const noexcept {
return ModInt(*this) += x;
}
constexpr ModInt operator-(const ModInt x) const noexcept {
return ModInt(*this) -= x;
}
constexpr ModInt operator*(const ModInt x) const noexcept {
return ModInt(*this) *= x;
}
constexpr ModInt operator/(const ModInt x) const noexcept {
return ModInt(*this) /= x;
}
constexpr ModInt &operator+=(const ModInt x) noexcept {
a += x.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt x) noexcept {
if (a < x.a) {
a += Modulus;
}
a -= x.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt x) noexcept {
a = a * x.a % Modulus;
return *this;
}
constexpr ModInt &operator/=(ModInt x) noexcept {
ll exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= x;
}
x *= x;
exp /= 2;
}
return *this;
}
constexpr ModInt operator-() noexcept { return ModInt(-a); }
friend ostream &operator<<(ostream &os, const ModInt &m) {
os << m.a;
return os;
}
};
using mint = ModInt<mod>;
bool check(ll h, ll r, const vector<ll> &a) {
ll lft = -1;
ll rgt = h;
REP_REV(i, sz(a)) {
if (i % 2 == 0) {
if (a[i] == 1) {
rgt--;
} else if (a[i] == -1) {
lft++;
}
} else {
if (a[i] == 1) {
lft--;
} else if (a[i] == -1) {
rgt++;
}
}
if (rgt - lft == 1)
return true;
if (lft < 0)
lft = -1;
if (rgt > h)
rgt = h;
}
return r <= lft || rgt <= r;
}
signed main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll h, w, n, r, c;
string s, t;
cin >> h >> w >> n >> r >> c >> s >> t;
vector<ll> x(2 * n), y(2 * n);
REP(i, n) {
if (s[i] == 'L') {
x[2 * i] = -1;
} else if (s[i] == 'R') {
x[2 * i] = 1;
} else if (s[i] == 'U') {
y[2 * i] = -1;
} else {
y[2 * i] = 1;
}
if (t[i] == 'L') {
x[2 * i + 1] = -1;
} else if (t[i] == 'R') {
x[2 * i + 1] = 1;
} else if (t[i] == 'U') {
y[2 * i + 1] = -1;
} else {
y[2 * i + 1] = 1;
}
}
if (check(h, r - 1, y)) {
cout << "NO" << endl;
} else if (check(w, c - 1, x)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 869,521 | 869,522 | u702582248 | cpp |
p03054 | #include <bits/stdc++.h>
#define pb push_back
#define pll pair<ll, ll>
#define mp make_pair
#define pyshnapyshnakaa \
ios_base ::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair<pair<ll, ll>, ll>
#define pllll pair<pair<ll, ll>, pair<ll, ll>>
#define psl pair<string, ll>
#define pld pair<ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector<vector<ll>>
#define cld complex<double>
typedef long long ll;
typedef long double ld;
using namespace std;
const ll maxn = 1e6 + 100;
const ll inf = 1e9;
ll n, m, k, t;
ll x, y;
int main() {
pyshnapyshnakaa ll q, w, e, a, b, c;
cin >> n >> m >> k;
string s1, s2;
cin >> x >> y;
x--;
y--;
cin >> s1 >> s2;
ll mn = m, mx = -1;
for (q = s1.size() - 1; q >= 0; q--) {
ll d1 = 0, d2 = 0;
if (s1[q] == 'L') {
d1 = -1;
}
if (s1[q] == 'R') {
d1 = 1;
}
if (s2[q] == 'L') {
d2 = -1;
}
if (s2[q] == 'R') {
d2 = 1;
}
if (d2 == -1) {
mn++;
mn = min(m, mn);
}
if (d2 == 1) {
mx--;
mx = max(-1LL, mx);
}
if (d1 == 1) {
mn--;
}
if (d1 == -1) {
mx++;
}
// cout << "D " << d1 << " " << d2 << endl;
// cout << q << " " << mn << " " << mx << endl;
// if (d1 == 1) {
// mn = min(mn, n - 1);
// }
// if (d1 == -1) {
// mx = max(mx, 0LL);
// }
if (mx >= mn - 1) {
cout << "NO";
return 0;
}
}
if (mn <= y || mx >= y) {
cout << "NO";
return 0;
}
// cout << "FIRST PASSED" << endl;
mn = n, mx = -1;
for (q = s1.size() - 1; q >= 0; q--) {
ll d1 = 0, d2 = 0;
if (s1[q] == 'U') {
d1 = -1;
}
if (s1[q] == 'D') {
d1 = 1;
}
if (s2[q] == 'U') {
d2 = -1;
}
if (s2[q] == 'D') {
d2 = 1;
}
if (d2 == -1) {
mn++;
mn = min(mn, n);
}
if (d2 == 1) {
mx--;
mx = max(mx, -1LL);
}
if (d1 == 1) {
mn--;
}
if (d1 == -1) {
mx++;
}
// cout << q << " " << mn << " " << mx << endl;
if (mx >= mn - 1) {
cout << "NO";
return 0;
}
}
if (mn <= y || mx >= y) {
cout << "NO";
return 0;
}
cout << "YES";
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define pll pair<ll, ll>
#define mp make_pair
#define pyshnapyshnakaa \
ios_base ::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair<pair<ll, ll>, ll>
#define pllll pair<pair<ll, ll>, pair<ll, ll>>
#define psl pair<string, ll>
#define pld pair<ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector<vector<ll>>
#define cld complex<double>
typedef long long ll;
typedef long double ld;
using namespace std;
const ll maxn = 1e6 + 100;
const ll inf = 1e9;
ll n, m, k, t;
ll x, y;
int main() {
pyshnapyshnakaa ll q, w, e, a, b, c;
cin >> n >> m >> k;
string s1, s2;
cin >> x >> y;
x--;
y--;
cin >> s1 >> s2;
ll mn = m, mx = -1;
for (q = s1.size() - 1; q >= 0; q--) {
ll d1 = 0, d2 = 0;
if (s1[q] == 'L') {
d1 = -1;
}
if (s1[q] == 'R') {
d1 = 1;
}
if (s2[q] == 'L') {
d2 = -1;
}
if (s2[q] == 'R') {
d2 = 1;
}
if (d2 == -1) {
mn++;
mn = min(m, mn);
}
if (d2 == 1) {
mx--;
mx = max(-1LL, mx);
}
if (d1 == 1) {
mn--;
}
if (d1 == -1) {
mx++;
}
// cout << "D " << d1 << " " << d2 << endl;
// cout << q << " " << mn << " " << mx << endl;
// if (d1 == 1) {
// mn = min(mn, n - 1);
// }
// if (d1 == -1) {
// mx = max(mx, 0LL);
// }
if (mx >= mn - 1) {
cout << "NO";
return 0;
}
}
if (mn <= y || mx >= y) {
cout << "NO";
return 0;
}
// cout << "FIRST PASSED" << endl;
mn = n, mx = -1;
for (q = s1.size() - 1; q >= 0; q--) {
ll d1 = 0, d2 = 0;
if (s1[q] == 'U') {
d1 = -1;
}
if (s1[q] == 'D') {
d1 = 1;
}
if (s2[q] == 'U') {
d2 = -1;
}
if (s2[q] == 'D') {
d2 = 1;
}
if (d2 == -1) {
mn++;
mn = min(mn, n);
}
if (d2 == 1) {
mx--;
mx = max(mx, -1LL);
}
if (d1 == 1) {
mn--;
}
if (d1 == -1) {
mx++;
}
// cout << q << " " << mn << " " << mx << endl;
if (mx >= mn - 1) {
cout << "NO";
return 0;
}
}
if (mn <= x || mx >= x) {
cout << "NO";
return 0;
}
cout << "YES";
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,528 | 869,529 | u051270344 | cpp |
p03054 | //
// main.cpp
// test130
//
// Created by on 2019/06/16.
// Copyright © 2 All rights reserved.
//
//
// main.cpp
// new
//
// Created on 2019/06/09.
// Copyright All rights reserved.
//
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define f(i, n) for (int i = 0; i < (n); i++)
#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)
using namespace std;
// Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % mod;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
// saidai-kouyakusuu
int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// Union-Find Tree
class Union_Find {
vector<int> par;
vector<int> rankmy;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rankmy[x] < rankmy[y]) {
par[x] = y;
} else {
par[y] = x;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
// Union-Find-End
// SegTree
template <class T> class SegTree {
int n; // 葉の数
vector<T> data; // データを格納するvector
T def; // 初期値かつ単位元
function<T(T, T)> operation; // 区間クエリで使う処理
function<T(T, T)> update; // 点更新で使う処理
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def; // 交差しない
if (a <= l && r <= b)
return data[k]; // a,l,r,bの順で完全に含まれる
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return operation(c1, c2);
}
}
public:
// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
// _update:更新関数
SegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
// 場所i(0-indexed)の値をxで更新
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)の区間クエリを実行
T query(int a, int b) { return _query(a, b, 0, 0, n); }
// 添字でアクセス
T operator[](int i) { return data[i + n - 1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
// Seg-Tree-End
// dfs
vector<int> v[100004];
bool went[100004];
void dfs(int x) {
went[x] = true;
for (int i = 0; i < v[x].size(); i++) {
if (!went[v[x][i]]) {
dfs(v[x][i]);
}
}
}
// Library-End
int h, w, n, fi, fj, tl, tr, tu, td, al, ar, au, ad, l, r, u, d;
string s, t;
signed main() {
cin >> h >> w >> n >> fi >> fj >> s >> t;
u = fi - 1;
d = h - fi;
l = fj - 1;
r = w - fj;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
tl++;
}
if (s[i] == 'R') {
tr++;
}
if (s[i] == 'U') {
tu++;
}
if (s[i] == 'D') {
td++;
}
if (tu - ad > u || td - au > d || tl - ar > l || tr - al > r) {
cout << "No" << endl;
return 0;
}
if (t[i] == 'L') {
if (al - tr <= l - 1)
al++;
}
if (t[i] == 'R') {
if (ar - tl <= r - 1)
ar++;
}
if (t[i] == 'U') {
if (au - td <= u - 1)
au++;
}
if (t[i] == 'D') {
if (ad - tu <= d - 1)
ad++;
}
}
cout << "Yes" << endl;
}
| //
// main.cpp
// test130
//
// Created by on 2019/06/16.
// Copyright © 2 All rights reserved.
//
//
// main.cpp
// new
//
// Created on 2019/06/09.
// Copyright All rights reserved.
//
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define f(i, n) for (int i = 0; i < (n); i++)
#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)
using namespace std;
// Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % mod;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
// saidai-kouyakusuu
int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// Union-Find Tree
class Union_Find {
vector<int> par;
vector<int> rankmy;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rankmy[x] < rankmy[y]) {
par[x] = y;
} else {
par[y] = x;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
// Union-Find-End
// SegTree
template <class T> class SegTree {
int n; // 葉の数
vector<T> data; // データを格納するvector
T def; // 初期値かつ単位元
function<T(T, T)> operation; // 区間クエリで使う処理
function<T(T, T)> update; // 点更新で使う処理
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def; // 交差しない
if (a <= l && r <= b)
return data[k]; // a,l,r,bの順で完全に含まれる
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return operation(c1, c2);
}
}
public:
// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
// _update:更新関数
SegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
// 場所i(0-indexed)の値をxで更新
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)の区間クエリを実行
T query(int a, int b) { return _query(a, b, 0, 0, n); }
// 添字でアクセス
T operator[](int i) { return data[i + n - 1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
// Seg-Tree-End
// dfs
vector<int> v[100004];
bool went[100004];
void dfs(int x) {
went[x] = true;
for (int i = 0; i < v[x].size(); i++) {
if (!went[v[x][i]]) {
dfs(v[x][i]);
}
}
}
// Library-End
int h, w, n, fi, fj, tl, tr, tu, td, al, ar, au, ad, l, r, u, d;
string s, t;
signed main() {
cin >> h >> w >> n >> fi >> fj >> s >> t;
u = fi - 1;
d = h - fi;
l = fj - 1;
r = w - fj;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
tl++;
}
if (s[i] == 'R') {
tr++;
}
if (s[i] == 'U') {
tu++;
}
if (s[i] == 'D') {
td++;
}
if (tu - ad > u || td - au > d || tl - ar > l || tr - al > r) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'L') {
if (al - tr <= l - 1)
al++;
}
if (t[i] == 'R') {
if (ar - tl <= r - 1)
ar++;
}
if (t[i] == 'U') {
if (au - td <= u - 1)
au++;
}
if (t[i] == 'D') {
if (ad - tu <= d - 1)
ad++;
}
}
cout << "YES" << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,537 | 869,538 | u943070796 | cpp |
p03054 | #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int H, W, N;
cin >> H >> W >> N;
int r, c;
cin >> r >> c;
string S, T;
cin >> S >> T;
int left = 1;
int right = W;
int up = 1;
int down = H;
if (S[N - 1] == 'L')
++left;
if (S[N - 1] == 'R')
--right;
if (S[N - 1] == 'U')
++up;
if (S[N - 1] == 'D')
--down;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L')
right = min(right + 1, W);
if (T[i] == 'R')
left = max(1, left - 1);
if (T[i] == 'U')
down = min(down + 1, H);
if (T[i] == 'D')
up = max(1, up - 1);
if (S[i] == 'R')
--right;
if (S[i] == 'L')
++left;
if (S[i] == 'D')
--down;
if (S[i] == 'U')
++up;
if (left > right || up > down) {
cout << "NO" << endl;
return 0;
}
}
if ((left <= c && c <= right) || (up <= r && r <= down)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int H, W, N;
cin >> H >> W >> N;
int r, c;
cin >> r >> c;
string S, T;
cin >> S >> T;
int left = 1;
int right = W;
int up = 1;
int down = H;
if (S[N - 1] == 'L')
++left;
if (S[N - 1] == 'R')
--right;
if (S[N - 1] == 'U')
++up;
if (S[N - 1] == 'D')
--down;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L')
right = min(right + 1, W);
if (T[i] == 'R')
left = max(1, left - 1);
if (T[i] == 'U')
down = min(down + 1, H);
if (T[i] == 'D')
up = max(1, up - 1);
if (S[i] == 'R')
--right;
if (S[i] == 'L')
++left;
if (S[i] == 'D')
--down;
if (S[i] == 'U')
++up;
if (left > right || up > down) {
cout << "NO" << endl;
return 0;
}
}
if ((left <= c && c <= right) && (up <= r && r <= down)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 869,541 | 869,542 | u004707990 | cpp |
p03054 | // Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector<int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() \
(IS == IT \
? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) \
: *IS++)
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
*OS++ = x;
if (OS == OT)
flush();
}
template <class I> inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
if (c == '-')
f = -1;
for (x = 0; c >= '0' && c <= '9';
x = (x << 3) + (x << 1) + (c & 15), c = gc())
;
x *= f;
}
template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); }
template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); }
template <class I> inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++)
rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc())
;
s[n + 1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc())
;
}
template <class I> inline void print(I x, char k = '\n') {
if (!x)
pc('0');
if (x < 0)
pc('-'), x = -x;
while (x)
ch[++t] = x % 10 + '0', x /= 10;
while (t)
pc(ch[t--]);
pc(k);
}
template <class I> inline void print(I x, I y) { print(x, ' '), print(y); }
template <class I> inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I> inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++)
print(a[i], " \n"[i == n]);
}
inline void printc(char c) { pc(c); }
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++)
pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n)
pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() { flush(); }
} flusher;
} // namespace io
using io::print;
using io::printa;
using io::printc;
using io::prints;
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
const int N = 2e5 + 7;
int n, m, k, x, y;
char a[N], b[N];
inline bool pd(int t, int w, char p, char q) {
for (int i = 1; i <= k; i++) {
if (a[i] == p)
--t;
if (!t)
return 0;
if (t != w && b[i] == q)
++t;
}
return 1;
}
int main() {
rd(n, m, k), rd(x, y), rds(a, k), rds(b, k);
if (!pd(x, n, 'U', 'D'))
return prints("No"), 0;
if (!pd(n - x + 1, n, 'D', 'U'))
return prints("No"), 0;
if (!pd(y, m, 'L', 'R'))
return prints("No"), 0;
if (!pd(m - y + 1, m, 'R', 'L'))
return prints("No"), 0;
prints("Yes");
return 0;
} | // Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector<int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() \
(IS == IT \
? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) \
: *IS++)
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
*OS++ = x;
if (OS == OT)
flush();
}
template <class I> inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
if (c == '-')
f = -1;
for (x = 0; c >= '0' && c <= '9';
x = (x << 3) + (x << 1) + (c & 15), c = gc())
;
x *= f;
}
template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); }
template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); }
template <class I> inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++)
rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc())
;
s[n + 1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc())
;
}
template <class I> inline void print(I x, char k = '\n') {
if (!x)
pc('0');
if (x < 0)
pc('-'), x = -x;
while (x)
ch[++t] = x % 10 + '0', x /= 10;
while (t)
pc(ch[t--]);
pc(k);
}
template <class I> inline void print(I x, I y) { print(x, ' '), print(y); }
template <class I> inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I> inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++)
print(a[i], " \n"[i == n]);
}
inline void printc(char c) { pc(c); }
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++)
pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n)
pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() { flush(); }
} flusher;
} // namespace io
using io::print;
using io::printa;
using io::printc;
using io::prints;
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
const int N = 2e5 + 7;
int n, m, k, x, y;
char a[N], b[N];
inline bool pd(int t, int w, char p, char q) {
for (int i = 1; i <= k; i++) {
if (a[i] == p)
--t;
if (!t)
return 0;
if (t != w && b[i] == q)
++t;
}
return 1;
}
int main() {
rd(n, m, k), rd(x, y), rds(a, k), rds(b, k);
if (!pd(x, n, 'U', 'D'))
return prints("NO"), 0;
if (!pd(n - x + 1, n, 'D', 'U'))
return prints("NO"), 0;
if (!pd(y, m, 'L', 'R'))
return prints("NO"), 0;
if (!pd(m - y + 1, m, 'R', 'L'))
return prints("NO"), 0;
prints("YES");
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"function.return_value.change",
"io.output.change"
] | 869,543 | 869,544 | u185303454 | cpp |
p03054 | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, h);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > x) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > x) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, h);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > h) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > h) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,545 | 869,546 | u639426108 | cpp |
p03054 | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, x);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > x) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > x) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, h);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > h) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > h) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"control_flow.branch.if.condition.change"
] | 869,547 | 869,546 | u639426108 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.