Datasets:

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
p03050
#include <algorithm> #include <assert.h> #include <bitset> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <string> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define TR(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define CLEAR(x) memset(x, 0, sizeof(x)) #define FILL(x, c) memset(x, c, sizeof(x)) using namespace std; const double eps = 1e-8; #define PB push_back #define MP make_pair typedef map<int, int> MII; typedef map<string, int> MSI; typedef vector<int> VI; typedef vector<string> VS; typedef vector<long double> VD; typedef pair<int, int> PII; typedef long long int64; typedef long long LL; typedef unsigned int UI; typedef long double LD; typedef unsigned long long ULL; int main() { LL n; cin >> n; if (n == 1) { cout << 0 << endl; return 0; } set<LL> res; for (int i = 1; i <= 2000000 && i <= n; ++i) { if ((n - i) % i == 0) { res.insert((n - i) / i); } } for (int i = 1; i <= 2000000; ++i) { if (n % (i + 1) == 0) { LL val = n / (i + 1); if (val < n) { res.insert(i); } } } LL ans = 0; TR(it, res) if (n / *it == n % *it) ans += *it; cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <string> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define TR(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define CLEAR(x) memset(x, 0, sizeof(x)) #define FILL(x, c) memset(x, c, sizeof(x)) using namespace std; const double eps = 1e-8; #define PB push_back #define MP make_pair typedef map<int, int> MII; typedef map<string, int> MSI; typedef vector<int> VI; typedef vector<string> VS; typedef vector<long double> VD; typedef pair<int, int> PII; typedef long long int64; typedef long long LL; typedef unsigned int UI; typedef long double LD; typedef unsigned long long ULL; int main() { LL n; cin >> n; if (n == 1) { cout << 0 << endl; return 0; } set<LL> res; for (int i = 1; i <= 2000000 && i < n; ++i) { if ((n - i) % i == 0) { res.insert((n - i) / i); } } for (int i = 1; i <= 2000000; ++i) { if (n % (i + 1) == 0) { LL val = n / (i + 1); if (val < n) { res.insert(i); } } } LL ans = 0; TR(it, res) if (n / *it == n % *it) ans += *it; cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
868,082
868,083
u061978627
cpp
p03050
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 0, n, i; cin >> n; for (i = 1; i * i < n; i++) if (n % i == 0) t += n / i - 1; cout << t; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 0, n, i; cin >> n; for (i = 1; i * (i + 1) < n; i++) if (n % i == 0) t += n / i - 1; cout << t; return 0; }
[ "control_flow.loop.for.condition.change" ]
868,086
868,087
u565087015
cpp
p03050
#include <cstdint> #include <iostream> using namespace std; // 575 int main() { int64_t N; cin >> N; int64_t ans = 0; for (int64_t i = 1; i * (i + 1) <= N; ++i) if ((N - i) % i == 0) ans += (N - i) / i; cout << ans; return 0; } /* 31536000のコメント解説欄 ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー 仮に商と余りを決め打つと答えが出しやすそう 商=余り=1なら、N=m+1かつm≧2だし 商=余り=2なら、N=2m+2かつm≧3だし 以下、同様に行うと√N通りだけ考えれば良いことが分かる 余りをiとする すると、N-iについてiの倍数なら、(N-i)/iがmであるから調べるだけ */
#include <cstdint> #include <iostream> using namespace std; // 575 int main() { int64_t N; cin >> N; int64_t ans = 0; for (int64_t i = 1; i * (i + 2) <= N; ++i) if ((N - i) % i == 0) ans += (N - i) / i; cout << ans; return 0; } /* 31536000のコメント解説欄 ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー 仮に商と余りを決め打つと答えが出しやすそう 商=余り=1なら、N=m+1かつm≧2だし 商=余り=2なら、N=2m+2かつm≧3だし 以下、同様に行うと√N通りだけ考えれば良いことが分かる 余りをiとする すると、N-iについてiの倍数なら、(N-i)/iがmであるから調べるだけ ループ条件は(N-i)/i≧i+1、よりN≧i(i+2) */
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
868,100
868,101
u550314572
cpp
p03050
#include <algorithm> #include <cstdio> #include <vector> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<ll>; using vvll = vector<vll>; int main(void) { ll n; while (scanf("%lld", &n) == 1) { ll ans = 0; for (ll m = 1; m * m < n; m++) { if ((n - m) % m == 0) { ans += (n - m) / m; } } printf("%lld\n", ans); } return 0; }
#include <algorithm> #include <cstdio> #include <vector> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<ll>; using vvll = vector<vll>; int main(void) { ll n; while (scanf("%lld", &n) == 1) { ll ans = 0; for (ll m = 1; m * (m + 1) < n; m++) { if ((n - m) % m == 0) { ans += (n - m) / m; } } printf("%lld\n", ans); } return 0; }
[ "control_flow.loop.condition.change", "control_flow.loop.for.condition.change" ]
868,106
868,107
u565795452
cpp
p03049
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define f0(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i <= n; i++) #define fc(i, c, n) for (i = c; i <= n; i++) #define f0r(i, n) for (i = n - 1; i >= 0; i--) #define f1r(i, n) for (i = n; i > 0; i--) #define fcr(i, c, n) for (i = n; i >= c; i--) #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef list<ll> LST; typedef vector<ll> VEC; typedef map<ll, ll> MAP; static int i, j, q; int main() { IO; // ifstream cin("In.txt"); ll n, m, ca = 0, cb = 0, cc = 0, ans = 0, tmp; string st; cin >> n; f0(i, n) { cin >> st; m = st.size(); if (st[0] == 'B' && st[m - 1] == 'A') cc++; else if (st[0] == 'B') cb++; else if (st[m - 1] == 'A') ca++; f1(j, m - 1) { if (st[j - 1] == 'A' && st[j] == 'B') ans++; } } if (ca || cb) { ans += cc + min(ca, cb); } else { ans += cc - 1; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define f0(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i <= n; i++) #define fc(i, c, n) for (i = c; i <= n; i++) #define f0r(i, n) for (i = n - 1; i >= 0; i--) #define f1r(i, n) for (i = n; i > 0; i--) #define fcr(i, c, n) for (i = n; i >= c; i--) #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef list<ll> LST; typedef vector<ll> VEC; typedef map<ll, ll> MAP; static int i, j, q; int main() { IO; // ifstream cin("In.txt"); ll n, m, ca = 0, cb = 0, cc = 0, ans = 0, tmp; string st; cin >> n; f0(i, n) { cin >> st; m = st.size(); if (st[0] == 'B' && st[m - 1] == 'A') cc++; else if (st[0] == 'B') cb++; else if (st[m - 1] == 'A') ca++; f1(j, m - 1) { if (st[j - 1] == 'A' && st[j] == 'B') ans++; } } if (ca || cb) { ans += cc + min(ca, cb); } else if (cc) { ans += cc - 1; } cout << ans << endl; return 0; }
[ "control_flow.branch.if.add" ]
868,119
868,120
u114738674
cpp
p03049
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define f0(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i <= n; i++) #define fc(i, c, n) for (i = c; i <= n; i++) #define f0r(i, n) for (i = n - 1; i >= 0; i--) #define f1r(i, n) for (i = n; i > 0; i--) #define fcr(i, c, n) for (i = n; i >= c; i--) #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef list<ll> LST; typedef vector<ll> VEC; typedef map<ll, ll> MAP; static int i, j, q; int main() { IO; // ifstream cin("In.txt"); ll n, m, ca = 0, cb = 0, cc = 0, ans = 0, tmp; string st; cin >> n; f0(i, n) { cin >> st; m = st.size(); if (st[0] == 'B' && st[m - 1] == 'A') cc++; else if (st[0] == 'B') cb++; else if (st[m - 1] == 'A') ca++; f1(j, m - 1) { if (st[j - 1] == 'A' && st[j] == 'B') ans++; } } if (ca || cc) { ans += cc + min(ca, cb); } else { ans += cc - 1; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define f0(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i <= n; i++) #define fc(i, c, n) for (i = c; i <= n; i++) #define f0r(i, n) for (i = n - 1; i >= 0; i--) #define f1r(i, n) for (i = n; i > 0; i--) #define fcr(i, c, n) for (i = n; i >= c; i--) #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef list<ll> LST; typedef vector<ll> VEC; typedef map<ll, ll> MAP; static int i, j, q; int main() { IO; // ifstream cin("In.txt"); ll n, m, ca = 0, cb = 0, cc = 0, ans = 0, tmp; string st; cin >> n; f0(i, n) { cin >> st; m = st.size(); if (st[0] == 'B' && st[m - 1] == 'A') cc++; else if (st[0] == 'B') cb++; else if (st[m - 1] == 'A') ca++; f1(j, m - 1) { if (st[j - 1] == 'A' && st[j] == 'B') ans++; } } if (ca || cb) { ans += cc + min(ca, cb); } else if (cc) { ans += cc - 1; } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change", "control_flow.branch.if.add" ]
868,121
868,120
u114738674
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { long long ea = 0, bb = 0, ch = 0, ans = 0, n, i, j; string s; cin >> n; for (i = 0; i < n; i++) { cin >> s; for (j = 0; j < s.size() - 1; j++) if (s[j] == 'A' && s[j + 1] == 'B') ans++; if (s[0] == 'B') bb++; if (s[s.size() - 1] == 'A') ea++; if (s[0] == 'B' && s[s.size() - 1] == 'A') ch++; } if (ch == bb && ch == ea) cout << ans + bb - 1 << endl; else cout << ans + min(bb, ea) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long ea = 0, bb = 0, ch = 0, ans = 0, n, i, j; string s; cin >> n; for (i = 0; i < n; i++) { cin >> s; for (j = 0; j < s.size() - 1; j++) if (s[j] == 'A' && s[j + 1] == 'B') ans++; if (s[0] == 'B') bb++; if (s[s.size() - 1] == 'A') ea++; if (s[0] == 'B' && s[s.size() - 1] == 'A') ch++; } if (ch == bb && ch == ea && ch > 0) cout << ans + bb - 1 << endl; else cout << ans + min(bb, ea) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,124
868,125
u038054933
cpp
p03049
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; string s[10000]; cin >> n; long long ans = 0; int a = 0; int b = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].length() - 1; j++) if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') ba++; else if (s[i][0] == 'B') b++; else if (s[i][s[i].length() - 1] == 'A') a++; } ans += ba - 1; if (ba == 0) ans += min(a, b); else if (b != 0 || a != 0) ans += min(a, b) + 1; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; string s[10000]; cin >> n; long long ans = 0; int a = 0; int b = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].length() - 1; j++) if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') ba++; else if (s[i][0] == 'B') b++; else if (s[i][s[i].length() - 1] == 'A') a++; } if (ba > 0) ans += ba - 1; if (ba == 0) ans += min(a, b); else if (b != 0 || a != 0) ans += min(a, b) + 1; cout << ans << endl; }
[ "control_flow.branch.if.add" ]
868,126
868,127
u702906718
cpp
p03049
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; string s[10000]; int sl[10000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; sl[i] = s[i].length(); s[i] = s[i].c_str(); } int countab = 0; int counta = 0; int countb = 0; int m = 0; for (int i = 0; i < n; i++) { bool a = false; bool b = false; if (s[i][0] == 'B') { countb++; b = true; } if (s[i][sl[i] - 1] == 'A') { counta++; a = true; } if (a == true && b == true) m++; for (int j = 0; j < sl[i] - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { countab++; } } } int ans = countab + min(counta, countb); if (counta == countb && m == counta) { ans--; } cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; string s[10000]; int sl[10000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; sl[i] = s[i].length(); s[i] = s[i].c_str(); } int countab = 0; int counta = 0; int countb = 0; int m = 0; for (int i = 0; i < n; i++) { bool a = false; bool b = false; if (s[i][0] == 'B') { countb++; b = true; } if (s[i][sl[i] - 1] == 'A') { counta++; a = true; } if (a == true && b == true) m++; for (int j = 0; j < sl[i] - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { countab++; } } } int ans = countab + min(counta, countb); if (counta == countb && m == counta && counta > 0) { ans--; } cout << ans << "\n"; }
[ "control_flow.branch.if.condition.change" ]
868,134
868,135
u155416173
cpp
p03049
#include <bits/stdc++.h> constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; using namespace std; using ll = long long int; using ull = unsigned long long int; // SA // BS // BA // BABS // SABABABS // BABA // BABABS // SABABA int main() { int N; cin >> N; int startB = 0, endA = 0, ans = 0, AandB = 0; for (int i = 0; i < N; i++) { string s; cin >> s; for (int j = 1; j < s.length(); j++) { if (s[j] == 'B' && s[j - 1] == 'A') ans++; } if (s[0] == 'B') startB++; if (s.back() == 'A') endA++; if (s[0] == 'B' && s.back() == 'A') AandB++; } startB -= AandB; endA -= AandB; if (endA != 0 && startB != 0) { cout << ans + AandB + min(startB - 1, endA - 1) + 1 << endl; } else if (endA == 0 && startB != 0) { cout << ans + AandB << endl; } else if (endA != 0 && startB == 0) { cout << ans + AandB << endl; } else { cout << ans + AandB - 1 << endl; } }
#include <bits/stdc++.h> constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; using namespace std; using ll = long long int; using ull = unsigned long long int; // AB + AB // ABAB // SA BA int main() { int N; cin >> N; int startB = 0, endA = 0, ans = 0, AandB = 0; for (int i = 0; i < N; i++) { string s; cin >> s; for (int j = 1; j < s.length(); j++) { if (s[j] == 'B' && s[j - 1] == 'A') ans++; } if (s[0] == 'B') startB++; if (s.back() == 'A') endA++; if (s[0] == 'B' && s.back() == 'A') AandB++; } startB -= AandB; endA -= AandB; if (endA != 0 && startB != 0) { cout << ans + AandB + min(startB - 1, endA - 1) + 1 << endl; } else if (endA == 0 && startB != 0) { cout << ans + AandB << endl; } else if (endA != 0 && startB == 0) { cout << ans + AandB << endl; } else { cout << ans + AandB - (AandB != 0) << endl; } }
[ "io.output.change" ]
868,136
868,137
u326966549
cpp
p03049
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; string s[10002]; int ans = 0; int fb = 0; int la = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; int l = s[i].size(); for (int j = 0; j < l - 1; j++) { if (s[i][j] == 'A') { if (s[i][j + 1] == 'B') ans++; } } if (s[i][0] == 'B') { fb++; if (s[i][l - 1] == 'A') ba++; } if (s[i][l - 1] == 'A') la++; } if (fb == la && fb == ba) ans = ans + fb - 1; else ans += min(fb, la); cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; string s[10002]; int ans = 0; int fb = 0; int la = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; int l = s[i].size(); for (int j = 0; j < l - 1; j++) { if (s[i][j] == 'A') { if (s[i][j + 1] == 'B') ans++; } } if (s[i][0] == 'B') { fb++; if (s[i][l - 1] == 'A') ba++; } if (s[i][l - 1] == 'A') la++; } if (fb == la && fb == ba && fb != 0) ans = ans + fb - 1; else ans += min(fb, la); cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
868,138
868,139
u681557252
cpp
p03049
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long llong; int N, A, B, C, D, ans; char s[10000][15]; bool flag = false, flagb = false; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> s[i]; flag = false; flagb = false; for (int j = 0;; j++) { if (j == 0 && s[i][j] == 'B') { A++; flagb = true; } if (flag && s[i][j] == 'B') { C++; flag = false; } else if (flag && s[i][j] == '\0') { B++; if (flagb) D++; break; } flag = false; if (s[i][j] == 'A') flag = true; if (s[i][j] == '\0') break; } } if (A == B && A == D) ans = C + A - 1; else ans = C + min(A, B); if (ans <= -1) cout << 0; else cout << ans; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long llong; int N, A, B, C, D, ans; char s[10000][15]; bool flag = false, flagb = false; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> s[i]; flag = false; flagb = false; for (int j = 0;; j++) { if (j == 0 && s[i][j] == 'B') { A++; flagb = true; } if (flag && s[i][j] == 'B') { C++; flag = false; } else if (flag && s[i][j] == '\0') { B++; if (flagb) D++; break; } flag = false; if (s[i][j] == 'A') flag = true; if (s[i][j] == '\0') break; } } if (A == B && A == D && A != 0) ans = C + A - 1; else ans = C + min(A, B); if (ans <= -1) cout << 0; else cout << ans; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,140
868,141
u740232619
cpp
p03049
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, ans = 0, a = 0, b = 0, c = 0; string s; string ab = "AB"; cin >> n; vector<string> v; for (int i = 0; i < n; i++) { cin >> s; v.emplace_back(s); } for (auto i : v) { auto r = i.begin(); while (r != i.end()) { r = search(r, i.end(), ab.begin(), ab.end()); if (r != i.end()) { r++; ans++; } } if (i.front() == 'B' && i.back() == 'A') c++; else if (i.front() == 'B') b++; else if (i.back() == 'A') a++; } if (c != 0) { ans += 2 * c - 2; if (a != 0) { ans++; a--; } if (b != 0) { ans++; b--; } } ans += min(a, b); cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, ans = 0, a = 0, b = 0, c = 0; string s; string ab = "AB"; cin >> n; vector<string> v; for (int i = 0; i < n; i++) { cin >> s; v.emplace_back(s); } for (auto i : v) { auto r = i.begin(); while (r != i.end()) { r = search(r, i.end(), ab.begin(), ab.end()); if (r != i.end()) { r++; ans++; } } if (i.front() == 'B' && i.back() == 'A') c++; else if (i.front() == 'B') b++; else if (i.back() == 'A') a++; } if (c != 0) { ans += c - 1; if (a != 0) { ans++; a--; } if (b != 0) { ans++; b--; } } ans += min(a, b); cout << ans << endl; }
[ "expression.operation.binary.remove", "literal.number.change", "assignment.value.change", "expression.operation.binary.change" ]
868,149
868,150
u324072562
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { #ifdef DEBUG std::ifstream in("/home/share/inputf.in"); std::cin.rdbuf(in.rdbuf()); #endif int N; int a = 0, b = 0, ab = 0, ans = 0; cin >> N; vector<string> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; for (int j = 0; j < S[i].size() - 1; j++) { if (S[i].substr(j, 2) == "AB") { ans++; } } if (S[i].front() == 'B' && S[i].back() == 'A') { ab++; } else if (S[i].back() == 'A') { a++; } else if (S[i].front() == 'B') { b++; } } if (a > 0 || b > 0) { if (a > 0 && b > 0) { ans += min(a, b) + ab; } else { ans += ab; } } else { ans += ab - 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { #ifdef DEBUG std::ifstream in("/home/share/inputf.in"); std::cin.rdbuf(in.rdbuf()); #endif int N; int a = 0, b = 0, ab = 0, ans = 0; cin >> N; vector<string> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; for (int j = 0; j < S[i].size() - 1; j++) { if (S[i].substr(j, 2) == "AB") { ans++; } } if (S[i].front() == 'B' && S[i].back() == 'A') { ab++; } else if (S[i].back() == 'A') { a++; } else if (S[i].front() == 'B') { b++; } } if (a > 0 || b > 0) { if (a > 0 && b > 0) { ans += min(a, b) + ab; } else { ans += ab; } } else { ans += max(ab - 1, 0); } cout << ans << endl; return 0; }
[ "call.add", "call.arguments.add" ]
868,154
868,155
u936555566
cpp
p03049
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define initdp(a, b) \ for (int i = 0; i <= a; i++) \ for (int j = 0; j <= b; j++) \ dp[i][j] = -1; #define fi first #define se second #define pb push_back #define pii pair<int, int> #define ll long long #define pll pair<ll, ll> #define rep(i, n) for (int i = 0; i < n; i++) #define repd(i, n) for (int i = n - 1; i >= 0; i--) #define waste \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define inf 1e9 + 1 #define inf1 1e18 + 1 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 1000005 #define mid(l, r) l + (r - l) / 2 void mad(ll &a, ll b) { a = (a + b) % mod; if (a < 0) a += mod; } using namespace std; void solve() { int n; cin >> n; string s[n]; int ans = 0; int st = 0, en = 0; int both = 0; rep(i, n) { cin >> s[i]; int nn = s[i].length(); rep(j, nn - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; } if (s[i][0] == 'B' && s[i][nn - 1] == 'A') both++; else if (s[i][0] == 'B') st++; else if (s[i][nn - 1] == 'A') en++; } if (both > 0) { ans += both - 1; both = 1; } else both = 0; int x = max(st, en); if (x) { st += both; en += both; ans += x; } cout << ans; } int main() { waste; int t; // cin>>t; t = 1; while (t--) { solve(); } }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define initdp(a, b) \ for (int i = 0; i <= a; i++) \ for (int j = 0; j <= b; j++) \ dp[i][j] = -1; #define fi first #define se second #define pb push_back #define pii pair<int, int> #define ll long long #define pll pair<ll, ll> #define rep(i, n) for (int i = 0; i < n; i++) #define repd(i, n) for (int i = n - 1; i >= 0; i--) #define waste \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define inf 1e9 + 1 #define inf1 1e18 + 1 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 1000005 #define mid(l, r) l + (r - l) / 2 void mad(ll &a, ll b) { a = (a + b) % mod; if (a < 0) a += mod; } using namespace std; void solve() { int n; cin >> n; string s[n]; int ans = 0; int st = 0, en = 0; int both = 0; rep(i, n) { cin >> s[i]; int nn = s[i].length(); rep(j, nn - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; } if (s[i][0] == 'B' && s[i][nn - 1] == 'A') both++; else if (s[i][0] == 'B') st++; else if (s[i][nn - 1] == 'A') en++; } if (both > 0) { ans += both - 1; both = 1; } else both = 0; int x = max(st, en); if (x) { st += both; en += both; ans += min(st, en); } cout << ans; } int main() { waste; int t; // cin>>t; t = 1; while (t--) { solve(); } }
[ "assignment.value.change", "call.arguments.add" ]
868,160
868,161
u133630059
cpp
p03049
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } char str[22]; int n, cnta, cntb, cntab; int main() { rd(n); int ans = 0; for (int i = 1; i <= n; ++i) { scanf("%s", str + 1); int len = strlen(str + 1); for (int j = 1; j < len; ++j) ans += str[j] == 'A' && str[j + 1] == 'B'; int ty = 0; if (str[1] == 'B') ty += 1; if (str[len] == 'A') ty += 2; /* if(ty==1) { if(cnta) cnta--,ans++; else if(cntab) cntab--,cntb++,ans++; else cntb++; } else if(ty==2) { if(cntb) cntb--,ans++; else if(cntab) cntab--,cnta++,ans++; else cnta++; } else if(ty==3) { if(cnta||cntb||cntab) ans++; else cntab++; }*/ if (ty == 1) cntb++; else if (ty == 2) cnta++; else if (ty == 3) cntab++; // cout<<cnta<<' '<<cntb<<' '<<cntab<<' '<<ans<<endl; } int t1 = min(cntb, cnta); if (t1) { ans += t1, cntb -= t1, cnta -= t1; ans += cntab; } else if (cnta + cntb) { ans += cntab; } else ans += cntab - 1; printf("%d", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } char str[22]; int n, cnta, cntb, cntab; int main() { rd(n); int ans = 0; for (int i = 1; i <= n; ++i) { scanf("%s", str + 1); int len = strlen(str + 1); for (int j = 1; j < len; ++j) ans += str[j] == 'A' && str[j + 1] == 'B'; int ty = 0; if (str[1] == 'B') ty += 1; if (str[len] == 'A') ty += 2; /* if(ty==1) { if(cnta) cnta--,ans++; else if(cntab) cntab--,cntb++,ans++; else cntb++; } else if(ty==2) { if(cntb) cntb--,ans++; else if(cntab) cntab--,cnta++,ans++; else cnta++; } else if(ty==3) { if(cnta||cntb||cntab) ans++; else cntab++; }*/ if (ty == 1) cntb++; else if (ty == 2) cnta++; else if (ty == 3) cntab++; // cout<<cnta<<' '<<cntb<<' '<<cntab<<' '<<ans<<endl; } int t1 = min(cntb, cnta); if (t1) { ans += t1, cntb -= t1, cnta -= t1; ans += cntab; } else if (cnta + cntb) { ans += cntab; } else if (cntab) ans += cntab - 1; printf("%d", ans); return 0; }
[ "control_flow.branch.if.add" ]
868,164
868,165
u973935896
cpp
p03049
#include <iostream> using namespace std; int find(string s) { int ans = 0, flag = 0; for (int i = 0; i < s.size(); i++) { if (flag) { if (s[i] == 'B') ans++; flag = 0; } if (s[i] == 'A') flag = 1; } return ans; } int main() { int n, ans = 0, a, b, c; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; ans += find(s); if (s[s.size() - 1] == 'A') a++; if (s[0] == 'B') b++; if (s[0] == 'B' && s[s.size() - 1] == 'A') c++; } // cout << a << endl << b << endl << c << endl; // cout << ans << endl; ans += min(a, b); // cout << ans << endl; if (c == a && c == b && c > 0) ans -= 1; cout << ans; return 0; }
#include <iostream> using namespace std; int find(string s) { int ans = 0, flag = 0; for (int i = 0; i < s.size(); i++) { if (flag) { if (s[i] == 'B') ans++; flag = 0; } if (s[i] == 'A') flag = 1; } return ans; } int main() { int n, ans = 0, a = 0, b = 0, c = 0; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; ans += find(s); if (s[s.size() - 1] == 'A') a++; if (s[0] == 'B') b++; if (s[0] == 'B' && s[s.size() - 1] == 'A') c++; } ans += min(a, b); if (c == a && c == b && c > 0) ans -= 1; cout << ans; return 0; }
[ "variable_declaration.value.change" ]
868,166
868,167
u261245192
cpp
p03049
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define RUP(a, b) ((a + b - 1) / (b)) #define SORTG(v) sort(v.begin(), v.end(), greater<>()) #define SORT(v) sort(v.begin(), v.end()) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple #define MOD 1000000007 #define INF LLONG_MAX / 3 typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<string> Vs; template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } void YesNo(int a) { if (a) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void YESNO(int a) { if (a) { cout << "YES" << endl; } else { cout << "NO" << endl; } } void AorB(int a, string b, string c) { if (a) { cout << b << endl; } else { cout << c << endl; } } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void start() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); } signed main() { start(); int n, x = 0, y = 0, z = 0, ans = 0; cin >> n; Vs s(n); REP(i, 0, n) { cin >> s[i]; REP(j, 0, s[i].size() - 1) if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') z++; else if (s[i][0] == 'B') y++; else if (s[i][s[i].size() - 1] == 'A') x++; } if (x > 0 && y > 0) ans += z + 1 + min(x - 1, y - 1); else if (x == 0 && y == 0) ans += z - 1; else ans += z; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define RUP(a, b) ((a + b - 1) / (b)) #define SORTG(v) sort(v.begin(), v.end(), greater<>()) #define SORT(v) sort(v.begin(), v.end()) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple #define MOD 1000000007 #define INF LLONG_MAX / 3 typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<string> Vs; template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } void YesNo(int a) { if (a) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void YESNO(int a) { if (a) { cout << "YES" << endl; } else { cout << "NO" << endl; } } void AorB(int a, string b, string c) { if (a) { cout << b << endl; } else { cout << c << endl; } } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void start() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); } signed main() { start(); int n, x = 0, y = 0, z = 0, ans = 0; cin >> n; Vs s(n); REP(i, 0, n) { cin >> s[i]; REP(j, 0, s[i].size() - 1) if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') z++; else if (s[i][0] == 'B') y++; else if (s[i][s[i].size() - 1] == 'A') x++; } if (x > 0 && y > 0) ans += z + 1 + min(x - 1, y - 1); else if (x == 0 && y == 0) ans += max(0LL, z - 1); else ans += z; cout << ans << endl; return 0; }
[ "call.add", "call.arguments.change" ]
868,168
868,169
u635484372
cpp
p03049
// khodaya khodet komak kon #include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<pll> vpl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll N = 2e5 + 10; const ll INF = 1e18; const ll LOG = 20; str a[N]; vector<pll> B; vector<pll> BAGH; ll ans[N]; ll CHECK(str s) { ll ans = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'A' && s[i + 1] == 'B') ans++; } return ans; } int main() { // IOS; ll n; cin >> n; ll Cnt = 0, Cnt1 = 0, Cnt2 = 0; ll an = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; an += CHECK(a[i]); if (a[i][0] != 'B' && a[i][a[i].size() - 1] == 'A') Cnt++; if (a[i][0] == 'B' && a[i][a[i].size() - 1] != 'A') Cnt1++; if (a[i][0] == 'B' && a[i][a[i].size() - 1] == 'A') Cnt2++; } // cout << an << '\n'; an += max((ll)0, Cnt2 - 1); // cout << an << '\n'; if (Cnt2 != 0) { if (Cnt != 0) an++; if (Cnt1 != 0) an++; Cnt--; Cnt1--; an += min(max(Cnt1, (ll)0), max(Cnt, (ll)0)); } else { an += min(Cnt1, Cnt2); } cout << an; return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
// khodaya khodet komak kon #include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<pll> vpl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll N = 2e5 + 10; const ll INF = 1e18; const ll LOG = 20; str a[N]; vector<pll> B; vector<pll> BAGH; ll ans[N]; ll CHECK(str s) { ll ans = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'A' && s[i + 1] == 'B') ans++; } return ans; } int main() { // IOS; ll n; cin >> n; ll Cnt = 0, Cnt1 = 0, Cnt2 = 0; ll an = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; an += CHECK(a[i]); if (a[i][0] != 'B' && a[i][a[i].size() - 1] == 'A') Cnt++; if (a[i][0] == 'B' && a[i][a[i].size() - 1] != 'A') Cnt1++; if (a[i][0] == 'B' && a[i][a[i].size() - 1] == 'A') Cnt2++; } // cout << an << '\n'; an += max((ll)0, Cnt2 - 1); // cout << an << '\n'; if (Cnt2 != 0) { if (Cnt != 0) an++; if (Cnt1 != 0) an++; Cnt--; Cnt1--; an += min(max(Cnt1, (ll)0), max(Cnt, (ll)0)); } else { an += min(Cnt1, Cnt); } cout << an; return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
[ "assignment.value.change", "identifier.change", "call.arguments.change" ]
868,170
868,171
u349705898
cpp
p03049
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> #define INF 1.0e9 using namespace std; typedef long long ll; int N; const int MAX_N = 10000; string s[MAX_N]; ll ans = 0; int hb = 0; int ta = 0; int allab = 0; void count_AB(string str) { int size = str.length(); if (str[0] == 'B') hb++; for (int i = 0; i < size - 1; i++) { if (str[i] == 'A' && str[i + 1] == 'B') ans++; } if (str[size - 1] == 'A') ta++; if (str[0] == 'B' && str[size - 1] == 'A') allab++; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) { count_AB(s[i]); } ans += min(hb, ta); if (ta == hb && allab == ta) ans = ans - 1; cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> #define INF 1.0e9 using namespace std; typedef long long ll; int N; const int MAX_N = 10000; string s[MAX_N]; ll ans = 0; int hb = 0; int ta = 0; int allab = 0; void count_AB(string str) { int size = str.length(); if (str[0] == 'B') hb++; for (int i = 0; i < size - 1; i++) { if (str[i] == 'A' && str[i + 1] == 'B') ans++; } if (str[size - 1] == 'A') ta++; if (str[0] == 'B' && str[size - 1] == 'A') allab++; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) { count_AB(s[i]); } ans += min(hb, ta); if (ta == hb && allab == ta && ta != 0) ans = ans - 1; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,172
868,173
u488352661
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> s(N); int A = 0; int B = 0; int AB = 0; int ans = 0; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][s[i].size() - 1] == 'A') { A++; } if (s[i][0] == 'B') { B++; } if (s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B') { AB++; } for (int j = 0; j < s[i].size() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; } } } if (max(A, B) == AB) { ans--; } cout << ans + min(A, B) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> s(N); int A = 0; int B = 0; int AB = 0; int ans = 0; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][s[i].size() - 1] == 'A') { A++; } if (s[i][0] == 'B') { B++; } if (s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B') { AB++; } for (int j = 0; j < s[i].size() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; } } } if (max(A, B) == AB && AB != 0) { ans--; } cout << ans + min(A, B) << endl; }
[ "control_flow.branch.if.condition.change" ]
868,174
868,175
u912534104
cpp
p03049
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define LL long long int main() { int n; cin >> n; int a = 0, b = 0, ab = 0; int ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s[0] == 'B' && s[s.length() - 1] == 'A') ab++; else if (s[0] == 'B') b++; else if (s[s.length() - 1] == 'A') a++; for (int k = 0; k < s.length() - 1; k++) { if (s[k] == 'A' && s[k + 1] == 'B') { k++; ans++; } } } // cout << "a " << a << " b " << b << " ab " << ab << endl; if (a == 0 && b == 0) { ans += ab - 1; } else { ans += min(a + ab, b + ab); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define LL long long int main() { int n; cin >> n; int a = 0, b = 0, ab = 0; int ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s[0] == 'B' && s[s.length() - 1] == 'A') ab++; else if (s[0] == 'B') b++; else if (s[s.length() - 1] == 'A') a++; for (int k = 0; k < s.length() - 1; k++) { if (s[k] == 'A' && s[k + 1] == 'B') { k++; ans++; } } // cout << "ans " << ans << endl; } // cout << "a " << a << " b " << b << " ab " << ab << endl; if (a == 0 && b == 0 && ab != 0) { ans += ab - 1; } else { ans += min(a + ab, b + ab); } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,180
868,181
u649423108
cpp
p03049
#pragma region _head #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <utility> #include <vector> void Init() { std::cin.tie(0); std::ios::sync_with_stdio(false); struct Init_caller { Init_caller() { Init(); } } caller; } #pragma region _define #define int LL #define f(i, a, b) for (LL i = a; i < b; i++) #define rep(i, n) for (LL i = 0; i < n; i++) #define rep2(i, j, a, h, w) \ for (LL i = 0; i < h; i++) \ for (LL j = 0; j < w; j++) \ cin >> a[i][j] #define f_vI(v, n) f(i, 0, n) cin >> v[i] #define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i] #define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i] #define f_vO(v, n) f(i, 0, n) cout << v[i] << endl #define ei else if #define all(a) a.begin(), a.end() #define size(s) ((LL)s.size()) #define F first #define S second #define check() cout << "! ! !" #define endl "\n" #define _y() cout << "Yes" << endl #define _Y() cout << "YES" << endl #define _n() cout << "No" << endl #define _N() cout << "NO" << endl #define INT_INF 1 << 29 #define LL_INF 1LL << 60 #define MOD 1000000007 #pragma endregion #pragma region _using using namespace std; using LL = long long; using st = string; 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 vc = vector<char>; using vvc = vector<vc>; using vs = vector<st>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using qi = queue<int>; using qc = queue<char>; using qs = queue<st>; using si = stack<int>; using sc = stack<char>; using ss = stack<st>; using pi = pair<int, int>; using ppi = pair<pi, int>; using mll = map<int, int>; using mcl = map<char, int>; using vpi = vector<pi>; using vppi = vector<ppi>; using qpi = queue<pi>; #pragma endregion //十字移動のみ int cross_x[] = {-1, 0, 0, 1}; int cross_y[] = {0, 1, -1, 0}; struct edge { int f, t, c; // from, to, cost }; void y_n(bool p) { p ? _y() : _n(); } void Y_N(bool p) { p ? _Y() : _N(); } LL vmax(vi v, LL n) { int MAX = 0; f(i, 0, n) { MAX = max(MAX, v[i]); } return MAX; } LL vmin(vi v, LL n) { int MIN = LL_INF; f(i, 0, n) { MIN = min(MIN, v[i]); } return MIN; } LL gcd(LL a, LL b) { if (b == 0) { swap(a, b); } LL r; while ((r = a % b) != 0) { a = b; b = r; } return b; } LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); } //素数判定 bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } //素因数分解 void dec_prime(int n) { int a = 2; while (a * a <= n) { if (n % a == 0) { cout << a << endl; n /= a; } else { a++; } } cout << n << endl; } //エラトステネスの篩 void sieve_prime(LL n) { vb s(n + 1, true); f(i, 2, n + 1) { for (int j = 2; i * j <= n; j++) { s[i * j] = false; } } cout << "2から" << n << "までの素数" << endl; f(i, 2, n + 1) { if (s[i]) { cout << i << " "; } } } //階乗計算 LL factorial(LL n) { LL a = 1, ret = 1; while (a < n) { a++; ret *= a; ret %= MOD; } return ret; } #pragma endregion vi par; int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(int x, int y) { if (root(x) == root(y)) { return; } else { par[root(x)] = root(y); return; } } bool same(int x, int y) { return root(x) == root(y); } /*****************************************************************************/ signed main() { int n; cin >> n; vs s(n); f_vI(s, n); int ab = 0; int taila = 0; int headb = 0; rep(i, n) { rep(j, size(s[i]) - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ab++; } if (j == size(s[i]) - 2) { if (s[i][j + 1] == 'A') { taila++; } } if (j == 0) { if (s[i][j] == 'B') { headb++; } } } } if (taila == n) { taila--; } cout << ab + min(taila, headb); return 0; }
#pragma region _head #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <utility> #include <vector> void Init() { std::cin.tie(0); std::ios::sync_with_stdio(false); struct Init_caller { Init_caller() { Init(); } } caller; } #pragma region _define #define int LL #define f(i, a, b) for (LL i = a; i < b; i++) #define rep(i, n) for (LL i = 0; i < n; i++) #define rep2(i, j, a, h, w) \ for (LL i = 0; i < h; i++) \ for (LL j = 0; j < w; j++) \ cin >> a[i][j] #define f_vI(v, n) f(i, 0, n) cin >> v[i] #define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i] #define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i] #define f_vO(v, n) f(i, 0, n) cout << v[i] << endl #define ei else if #define all(a) a.begin(), a.end() #define size(s) ((LL)s.size()) #define F first #define S second #define check() cout << "! ! !" #define endl "\n" #define _y() cout << "Yes" << endl #define _Y() cout << "YES" << endl #define _n() cout << "No" << endl #define _N() cout << "NO" << endl #define INT_INF 1 << 29 #define LL_INF 1LL << 60 #define MOD 1000000007 #pragma endregion #pragma region _using using namespace std; using LL = long long; using st = string; 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 vc = vector<char>; using vvc = vector<vc>; using vs = vector<st>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using qi = queue<int>; using qc = queue<char>; using qs = queue<st>; using si = stack<int>; using sc = stack<char>; using ss = stack<st>; using pi = pair<int, int>; using ppi = pair<pi, int>; using mll = map<int, int>; using mcl = map<char, int>; using vpi = vector<pi>; using vppi = vector<ppi>; using qpi = queue<pi>; #pragma endregion //十字移動のみ int cross_x[] = {-1, 0, 0, 1}; int cross_y[] = {0, 1, -1, 0}; struct edge { int f, t, c; // from, to, cost }; void y_n(bool p) { p ? _y() : _n(); } void Y_N(bool p) { p ? _Y() : _N(); } LL vmax(vi v, LL n) { int MAX = 0; f(i, 0, n) { MAX = max(MAX, v[i]); } return MAX; } LL vmin(vi v, LL n) { int MIN = LL_INF; f(i, 0, n) { MIN = min(MIN, v[i]); } return MIN; } LL gcd(LL a, LL b) { if (b == 0) { swap(a, b); } LL r; while ((r = a % b) != 0) { a = b; b = r; } return b; } LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); } //素数判定 bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } //素因数分解 void dec_prime(int n) { int a = 2; while (a * a <= n) { if (n % a == 0) { cout << a << endl; n /= a; } else { a++; } } cout << n << endl; } //エラトステネスの篩 void sieve_prime(LL n) { vb s(n + 1, true); f(i, 2, n + 1) { for (int j = 2; i * j <= n; j++) { s[i * j] = false; } } cout << "2から" << n << "までの素数" << endl; f(i, 2, n + 1) { if (s[i]) { cout << i << " "; } } } //階乗計算 LL factorial(LL n) { LL a = 1, ret = 1; while (a < n) { a++; ret *= a; // ret %= MOD; } return ret; } #pragma endregion vi par; int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(int x, int y) { if (root(x) == root(y)) { return; } else { par[root(x)] = root(y); return; } } bool same(int x, int y) { return root(x) == root(y); } /*****************************************************************************/ signed main() { int n; cin >> n; vs s(n); f_vI(s, n); int ab = 0; int taila = 0; int headb = 0; rep(i, n) { rep(j, size(s[i]) - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { s[i][j] = '#'; s[i][j + 1] = '#'; ab++; } } } vs ss(n); rep(i, n) { ss[i].push_back(s[i][0]); ss[i].push_back(s[i][size(s[i]) - 1]); } int BA = 0; rep(i, n) { if (ss[i][1] == 'A') { taila++; } if (ss[i][0] == 'B') { headb++; } if (ss[i] == "BA") { BA++; } } // cout << ab << " " << taila << " "<<headb << endl; int ans = ab + min(headb, taila); if (BA != 0 && BA == taila && BA == headb) { ans--; } cout << ans; return 0; }
[]
868,194
868,195
u987267288
cpp
p03049
#pragma region _head #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <utility> #include <vector> void Init() { std::cin.tie(0); std::ios::sync_with_stdio(false); struct Init_caller { Init_caller() { Init(); } } caller; } #pragma region _define #define int LL #define f(i, a, b) for (LL i = a; i < b; i++) #define rep(i, n) for (LL i = 0; i < n; i++) #define rep2(i, j, a, h, w) \ for (LL i = 0; i < h; i++) \ for (LL j = 0; j < w; j++) \ cin >> a[i][j] #define f_vI(v, n) f(i, 0, n) cin >> v[i] #define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i] #define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i] #define f_vO(v, n) f(i, 0, n) cout << v[i] << endl #define ei else if #define all(a) a.begin(), a.end() #define size(s) ((LL)s.size()) #define F first #define S second #define check() cout << "! ! !" #define endl "\n" #define _y() cout << "Yes" << endl #define _Y() cout << "YES" << endl #define _n() cout << "No" << endl #define _N() cout << "NO" << endl #define INT_INF 1 << 29 #define LL_INF 1LL << 60 #define MOD 1000000007 #pragma endregion #pragma region _using using namespace std; using LL = long long; using st = string; 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 vc = vector<char>; using vvc = vector<vc>; using vs = vector<st>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using qi = queue<int>; using qc = queue<char>; using qs = queue<st>; using si = stack<int>; using sc = stack<char>; using ss = stack<st>; using pi = pair<int, int>; using ppi = pair<pi, int>; using mll = map<int, int>; using mcl = map<char, int>; using vpi = vector<pi>; using vppi = vector<ppi>; using qpi = queue<pi>; #pragma endregion //十字移動のみ int cross_x[] = {-1, 0, 0, 1}; int cross_y[] = {0, 1, -1, 0}; struct edge { int f, t, c; // from, to, cost }; void y_n(bool p) { p ? _y() : _n(); } void Y_N(bool p) { p ? _Y() : _N(); } LL vmax(vi v, LL n) { int MAX = 0; f(i, 0, n) { MAX = max(MAX, v[i]); } return MAX; } LL vmin(vi v, LL n) { int MIN = LL_INF; f(i, 0, n) { MIN = min(MIN, v[i]); } return MIN; } LL gcd(LL a, LL b) { if (b == 0) { swap(a, b); } LL r; while ((r = a % b) != 0) { a = b; b = r; } return b; } LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); } //素数判定 bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } //素因数分解 void dec_prime(int n) { int a = 2; while (a * a <= n) { if (n % a == 0) { cout << a << endl; n /= a; } else { a++; } } cout << n << endl; } //エラトステネスの篩 void sieve_prime(LL n) { vb s(n + 1, true); f(i, 2, n + 1) { for (int j = 2; i * j <= n; j++) { s[i * j] = false; } } cout << "2から" << n << "までの素数" << endl; f(i, 2, n + 1) { if (s[i]) { cout << i << " "; } } } //階乗計算 LL factorial(LL n) { LL a = 1, ret = 1; while (a < n) { a++; ret *= a; ret %= MOD; } return ret; } #pragma endregion vi par; int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(int x, int y) { if (root(x) == root(y)) { return; } else { par[root(x)] = root(y); return; } } bool same(int x, int y) { return root(x) == root(y); } /*****************************************************************************/ signed main() { int n; cin >> n; vs s(n); f_vI(s, n); int ab = 0; int taila = 0; int headb = 0; rep(i, n) { rep(j, size(s[i]) - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ab++; } if (j == size(s[i]) - 2) { if (s[i][j + 1] == 'A') { taila++; } } if (j == 0) { if (s[i][j] == 'B') { headb++; } } } } cout << ab + (taila + headb) / 2; return 0; }
#pragma region _head #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <utility> #include <vector> void Init() { std::cin.tie(0); std::ios::sync_with_stdio(false); struct Init_caller { Init_caller() { Init(); } } caller; } #pragma region _define #define int LL #define f(i, a, b) for (LL i = a; i < b; i++) #define rep(i, n) for (LL i = 0; i < n; i++) #define rep2(i, j, a, h, w) \ for (LL i = 0; i < h; i++) \ for (LL j = 0; j < w; j++) \ cin >> a[i][j] #define f_vI(v, n) f(i, 0, n) cin >> v[i] #define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i] #define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i] #define f_vO(v, n) f(i, 0, n) cout << v[i] << endl #define ei else if #define all(a) a.begin(), a.end() #define size(s) ((LL)s.size()) #define F first #define S second #define check() cout << "! ! !" #define endl "\n" #define _y() cout << "Yes" << endl #define _Y() cout << "YES" << endl #define _n() cout << "No" << endl #define _N() cout << "NO" << endl #define INT_INF 1 << 29 #define LL_INF 1LL << 60 #define MOD 1000000007 #pragma endregion #pragma region _using using namespace std; using LL = long long; using st = string; 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 vc = vector<char>; using vvc = vector<vc>; using vs = vector<st>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using qi = queue<int>; using qc = queue<char>; using qs = queue<st>; using si = stack<int>; using sc = stack<char>; using ss = stack<st>; using pi = pair<int, int>; using ppi = pair<pi, int>; using mll = map<int, int>; using mcl = map<char, int>; using vpi = vector<pi>; using vppi = vector<ppi>; using qpi = queue<pi>; #pragma endregion //十字移動のみ int cross_x[] = {-1, 0, 0, 1}; int cross_y[] = {0, 1, -1, 0}; struct edge { int f, t, c; // from, to, cost }; void y_n(bool p) { p ? _y() : _n(); } void Y_N(bool p) { p ? _Y() : _N(); } LL vmax(vi v, LL n) { int MAX = 0; f(i, 0, n) { MAX = max(MAX, v[i]); } return MAX; } LL vmin(vi v, LL n) { int MIN = LL_INF; f(i, 0, n) { MIN = min(MIN, v[i]); } return MIN; } LL gcd(LL a, LL b) { if (b == 0) { swap(a, b); } LL r; while ((r = a % b) != 0) { a = b; b = r; } return b; } LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); } //素数判定 bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } //素因数分解 void dec_prime(int n) { int a = 2; while (a * a <= n) { if (n % a == 0) { cout << a << endl; n /= a; } else { a++; } } cout << n << endl; } //エラトステネスの篩 void sieve_prime(LL n) { vb s(n + 1, true); f(i, 2, n + 1) { for (int j = 2; i * j <= n; j++) { s[i * j] = false; } } cout << "2から" << n << "までの素数" << endl; f(i, 2, n + 1) { if (s[i]) { cout << i << " "; } } } //階乗計算 LL factorial(LL n) { LL a = 1, ret = 1; while (a < n) { a++; ret *= a; // ret %= MOD; } return ret; } #pragma endregion vi par; int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(int x, int y) { if (root(x) == root(y)) { return; } else { par[root(x)] = root(y); return; } } bool same(int x, int y) { return root(x) == root(y); } /*****************************************************************************/ signed main() { int n; cin >> n; vs s(n); f_vI(s, n); int ab = 0; int taila = 0; int headb = 0; rep(i, n) { rep(j, size(s[i]) - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { s[i][j] = '#'; s[i][j + 1] = '#'; ab++; } } } vs ss(n); rep(i, n) { ss[i].push_back(s[i][0]); ss[i].push_back(s[i][size(s[i]) - 1]); } int BA = 0; rep(i, n) { if (ss[i][1] == 'A') { taila++; } if (ss[i][0] == 'B') { headb++; } if (ss[i] == "BA") { BA++; } } // cout << ab << " " << taila << " "<<headb << endl; int ans = ab + min(headb, taila); if (BA != 0 && BA == taila && BA == headb) { ans--; } cout << ans; return 0; }
[]
868,196
868,195
u987267288
cpp
p03049
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; int A = 0; int B = 0; int count = 0; int check = 0; for (int i = 0; i < N; i++) { string s; cin >> s; int M; M = s.size(); if (s.at(0) == 'B') { B++; } if (s.at(M - 1) == 'A') { A++; } if (s.at(0) == 'B' && s.at(M - 1) == 'A') { check++; } for (int j = 0; j < M; j++) { if (j != M - 1 && s.at(j) == 'A' && s.at(j + 1) == 'B') { count++; } } } count += min(A, B); if (A == B && B == check) { count--; } cout << count << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; int A = 0; int B = 0; int count = 0; int check = 0; for (int i = 0; i < N; i++) { string s; cin >> s; int M; M = s.size(); if (s.at(0) == 'B') { B++; } if (s.at(M - 1) == 'A') { A++; } if (s.at(0) == 'B' && s.at(M - 1) == 'A') { check++; } for (int j = 0; j < M; j++) { if (j != M - 1 && s.at(j) == 'A' && s.at(j + 1) == 'B') { count++; } } } count += min(A, B); if (A == B && B == check && check != 0) { count--; } cout << count << endl; }
[ "control_flow.branch.if.condition.change" ]
868,197
868,198
u913104858
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int startb = 0, enda = 0, inab = 0; bool loop = true; for (int i = 0; i < n; ++i) { string s; cin >> s; int x = s.size(); if (s[0] == 'B') { ++startb; if (s[x - 1] != 'A') loop = false; } if (s[x - 1] == 'A') { ++enda; if (s[0] != 'B') loop = false; } for (int j = 0; j < x - 1; ++j) { if (s[j] == 'A' && s[j + 1] == 'B') ++inab; } } int ans = 0; if (startb == enda && loop) ans = inab + startb - 1; else ans = inab + min(startb, enda); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int startb = 0, enda = 0, inab = 0; bool loop = true; for (int i = 0; i < n; ++i) { string s; cin >> s; int x = s.size(); if (s[0] == 'B') { ++startb; if (s[x - 1] != 'A') loop = false; } if (s[x - 1] == 'A') { ++enda; if (s[0] != 'B') loop = false; } for (int j = 0; j < x - 1; ++j) { if (s[j] == 'A' && s[j + 1] == 'B') ++inab; } } int ans = 0; if (startb == enda && startb > 0 && loop) ans = inab + startb - 1; else ans = inab + min(startb, enda); cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
868,202
868,203
u640800420
cpp
p03049
#include <algorithm> #include <iostream> #include <string> #include <vector> struct result { bool head_b, tail_a; int count; result(const std::string &s, int index_) : head_b{s[0] == 'B'}, tail_a{s.back() == 'A'}, count{} { auto pos = s.find("AB"); while (pos != std::string::npos) { ++count; pos = s.find("AB", pos + 1); } } friend auto operator<<(std::ostream &os, const result &r) -> std::ostream & { return os << (r.head_b ? 'T' : 'F') << ", " << (r.tail_a ? 'T' : 'F') << ", " << r.count; } explicit operator bool() const { return this->head_b && this->tail_a; } }; int main() { int n; std::cin >> n; std::vector<std::string> vs(n); std::vector<result> vr; vr.reserve(n); int ac{}, bc{}, abc{}, count{}; for (int i{}; i < n; ++i) { std::string t; std::cin >> t; vr.emplace_back(t, i); // std::cout << vr[i]<<"\n"; ac += vr[i].tail_a ? 1 : 0; bc += vr[i].head_b ? 1 : 0; abc += vr[i] ? 1 : 0; count += vr[i].count; } // std::cout << ac << " " << bc << " " << abc <<" "<< count<<"\n"; auto m_ = std::min(ac, bc); auto ans = m_ - (abc == ac && bc == abc ? 1 : 0) + count; std::cout << ans << "\n"; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> struct result { bool head_b, tail_a; int count; result(const std::string &s, int index_) : head_b{s[0] == 'B'}, tail_a{s.back() == 'A'}, count{} { auto pos = s.find("AB"); while (pos != std::string::npos) { ++count; pos = s.find("AB", pos + 1); } } friend auto operator<<(std::ostream &os, const result &r) -> std::ostream & { return os << (r.head_b ? 'T' : 'F') << ", " << (r.tail_a ? 'T' : 'F') << ", " << r.count; } explicit operator bool() const { return this->head_b && this->tail_a; } }; int main() { int n; std::cin >> n; std::vector<std::string> vs(n); std::vector<result> vr; vr.reserve(n); int ac{}, bc{}, abc{}, count{}; for (int i{}; i < n; ++i) { std::string t; std::cin >> t; vr.emplace_back(t, i); // std::cout << vr[i]<<"\n"; ac += vr[i].tail_a ? 1 : 0; bc += vr[i].head_b ? 1 : 0; abc += vr[i] ? 1 : 0; count += vr[i].count; } // std::cout << ac << " " << bc << " " << abc <<" "<< count<<"\n"; auto m_ = std::min(ac, bc); auto ans = m_ - (abc > 0 && abc == ac && bc == abc ? 1 : 0) + count; std::cout << ans << "\n"; return 0; }
[ "assignment.change" ]
868,206
868,207
u837286475
cpp
p03049
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define ll long long #define ld long double #define fi first //#define endl "\n" #define se second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define loop(i, a, b) for (ll i = a; i < b; i++) #define initialize(array, size, value) \ for (ll i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (ll i = 0; i < size; i++) \ cout << array[i] << " " #define debug(x) cout << "x: " << x << endl #define dbug(x, y) \ cout << "x: " << x << " " \ << "y: " << y << endl #define inf (long long int)1e18 #define eps 0.000001 #define vl vector<ll> #define sl set<ll> #define pll pair<ll, ll> #define mll map<ll, ll> #define pq priority_queue<ll> #define mod 1000000007 #define MAXN 100001 typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; ll spf[MAXN]; ll gcd(ll a, ll b); ll palindrome(string s); ll modexp(ll a, ll b, ll m); void sieve(); ll ceil(ll a, ll b); vl getFactorization(ll x); void getZarr(string str, ll Z[]); vector<ll> prefix_function(string s); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ll n; cin >> n; string s[n]; loop(i, 0, n) cin >> s[i]; char st[n], en[n]; loop(i, 0, n) { st[i] = s[i][0]; en[i] = s[i][s[i].length() - 1]; } ll c1 = 0, c2 = 0, c3 = 0, c4 = 0; loop(i, 0, n) { if (st[i] != 'B' && en[i] == 'A') { c1++; } else if (st[i] == 'B' && en[i] == 'A') c2++; else if (st[i] == 'B' && en[i] != 'A') c3++; } ll ans = 0; loop(i, 0, n) { loop(j, 0, s[i].length() - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; j++; } } } /*cout<<ans<<endl; cout<<c1<<" "<<c2<<" "<<c3<<endl;*/ if (c1 > 0) { ans = ans + c2; c1--; if (c3 > 0) { ans++; c3--; } ans = ans + max((ll)0, min(c1, c3)); } else { ans += max((ll)0, c2 - 1); if (c3 > 0) { ans++; c3--; } ans = ans + max((ll)0, min(c1, c3)); } cout << ans << endl; } ll gcd(ll a, ll b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a % b, b); return gcd(a, b % a); } ll palindrome(string s) { ll l = 0; ll h = s.length() - 1; while (h > l) { if (s[l++] != s[h--]) { return 0; } } return 1; } ll modexp(ll a, ll b, ll m) { if (b == 0) return 1; ll temp = modexp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a return temp; } void sieve() { spf[1] = 1; for (ll i = 2; i < MAXN; i++) spf[i] = i; for (ll i = 4; i < MAXN; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXN; j += i) if (spf[j] == j) spf[j] = i; } } }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define ll long long #define ld long double #define fi first //#define endl "\n" #define se second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define loop(i, a, b) for (ll i = a; i < b; i++) #define initialize(array, size, value) \ for (ll i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (ll i = 0; i < size; i++) \ cout << array[i] << " " #define debug(x) cout << "x: " << x << endl #define dbug(x, y) \ cout << "x: " << x << " " \ << "y: " << y << endl #define inf (long long int)1e18 #define eps 0.000001 #define vl vector<ll> #define sl set<ll> #define pll pair<ll, ll> #define mll map<ll, ll> #define pq priority_queue<ll> #define mod 1000000007 #define MAXN 100001 typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; ll spf[MAXN]; ll gcd(ll a, ll b); ll palindrome(string s); ll modexp(ll a, ll b, ll m); void sieve(); ll ceil(ll a, ll b); vl getFactorization(ll x); void getZarr(string str, ll Z[]); vector<ll> prefix_function(string s); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ll n; cin >> n; string s[n]; loop(i, 0, n) cin >> s[i]; char st[n], en[n]; loop(i, 0, n) { st[i] = s[i][0]; en[i] = s[i][s[i].length() - 1]; } ll c1 = 0, c2 = 0, c3 = 0, c4 = 0; loop(i, 0, n) { if (st[i] != 'B' && en[i] == 'A') { c1++; } else if (st[i] == 'B' && en[i] == 'A') c2++; else if (st[i] == 'B' && en[i] != 'A') c3++; } ll ans = 0; loop(i, 0, n) { loop(j, 0, s[i].length() - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; j++; } } } /*cout<<ans<<endl; cout<<c1<<" "<<c2<<" "<<c3<<endl;*/ if (c1 > 0) { ans = ans + c2; c1--; if (c3 > 0) { ans++; c3--; } ans = ans + max((ll)0, min(c1, c3)); } else { ans += max((ll)0, c2 - 1); if (c3 > 0 && c2 > 0) { ans++; c3--; } ans = ans + max((ll)0, min(c1, c3)); } cout << ans << endl; } ll gcd(ll a, ll b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a % b, b); return gcd(a, b % a); } ll palindrome(string s) { ll l = 0; ll h = s.length() - 1; while (h > l) { if (s[l++] != s[h--]) { return 0; } } return 1; } ll modexp(ll a, ll b, ll m) { if (b == 0) return 1; ll temp = modexp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a return temp; } void sieve() { spf[1] = 1; for (ll i = 2; i < MAXN; i++) spf[i] = i; for (ll i = 4; i < MAXN; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXN; j += i) if (spf[j] == j) spf[j] = i; } } }
[ "control_flow.branch.if.condition.change" ]
868,208
868,209
u851993789
cpp
p03049
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n; cin >> n; int ba = 0, a = 0, b = 0, c = 0; for (int i = 0; i < n; i++) { string s; cin >> s; bool bb = false; bool aa = false; for (int j = 0; j < (int)s.size(); j++) { if (j == 0 && s[j] == 'B') bb = true; else if (j != 0 && (s[j - 1] == 'A' && s[j] == 'B')) c++; else if (j == (int)s.size() - 1 && s[j] == 'A') aa = true; } if (aa && bb) ba++; else if (aa) a++; else if (bb) b++; } int ans = c + min(a, b) + ba; if (!a && !b) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n; cin >> n; int ba = 0, a = 0, b = 0, c = 0; for (int i = 0; i < n; i++) { string s; cin >> s; bool bb = false; bool aa = false; for (int j = 0; j < (int)s.size(); j++) { if (j == 0 && s[j] == 'B') bb = true; else if (j != 0 && (s[j - 1] == 'A' && s[j] == 'B')) c++; else if (j == (int)s.size() - 1 && s[j] == 'A') aa = true; } if (aa && bb) ba++; else if (aa) a++; else if (bb) b++; } int ans = c + min(a, b) + ba; if (!a && !b && ba) ans--; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,210
868,211
u036561304
cpp
p03049
#include <iostream> #include <map> #include <math.h> #include <string> using namespace std; #define ll long long int main() { int N, ans = 0, BA = 0; cin >> N; int count[N] = {}, headb[N] = {}, enda[N] = {}; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][0] == 'B') headb[i] = 1; if (s[i][s[i].length() - 1] == 'A') enda[i] = 1; if (headb[i] && enda[i]) BA++; for (int j = 0; j < s[i].length() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') count[i]++; } } for (int i = 1; i < N; i++) { headb[0] += headb[i]; enda[0] += enda[i]; count[0] += count[i]; } ans = count[0] + (headb[0] > enda[0] ? enda[0] : headb[0]); if (BA == headb[0] && BA == enda[0]) ans--; cout << ans << endl; return 0; }
#include <iostream> #include <map> #include <math.h> #include <string> using namespace std; #define ll long long int main() { int N, ans = 0, BA = 0; cin >> N; int count[N] = {}, headb[N] = {}, enda[N] = {}; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][0] == 'B') headb[i] = 1; if (s[i][s[i].length() - 1] == 'A') enda[i] = 1; if (headb[i] && enda[i]) BA++; for (int j = 0; j < s[i].length() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') count[i]++; } } for (int i = 1; i < N; i++) { headb[0] += headb[i]; enda[0] += enda[i]; count[0] += count[i]; } ans = count[0] + (headb[0] > enda[0] ? enda[0] : headb[0]); if (BA && BA == headb[0] && BA == enda[0]) ans--; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,213
868,214
u668443884
cpp
p03049
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <algorithm> #include <bits/stdc++.h> #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> using namespace std; #define int long long #define ll long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define mp make_pair #define all(a) (a).begin(), (a).end() #define FF first #define SS second #define sz(x) (int)x.size() #define endl '\n' //#define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) // mp::cpp_int #define pp pair<pii, pii> const int hell = 1000000007; int power(int a, int b) { if (b == 0) return 1; if (b == 1) return a; int t = power(a, b / 2); t %= hell; t *= t; t %= hell; if (b % 2) return (t * a) % hell; else return t; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b - a % b, a % b); } int digitsum(int x) { while (x > 9) { int ans = 0; while (x != 0) { ans += x % 10; x /= 10; } x = ans; } return x; } int pw(int a, int b) { int x = a; rep(i, 1, b) { a = a * x; } return a; } int cnt = 0; void computeLPSArray(string pat, int M, int lps[]) { int len = 0; lps[0] = 0; // lps[0] is always 0 // the loop calculates lps[i] for i = 1 to M-1 int i = 1; while (i < M) { if (pat[i] == pat[len]) { len++; lps[i] = len; i++; } else // (pat[i] != pat[len]) { // This is tricky. Consider the example. // AAACAAAA and i = 7. The idea is similar // to search step. if (len != 0) { len = lps[len - 1]; // Also, note that we do not increment // i here } else // if (len == 0) { lps[i] = 0; i++; } } } } // Prints occurrences of txt[] in pat[] void KMPSearch(string pat, string txt) { int M = pat.size(); int N = txt.size(); // create lps[] that will hold the longest prefix suffix // values for pattern int lps[M]; // Preprocess the pattern (calculate lps[] array) computeLPSArray(pat, M, lps); int i = 0; // index for txt[] int j = 0; // index for pat[] while (i < N) { if (pat[j] == txt[i]) { j++; i++; } if (j == M) { cnt++; j = lps[j - 1]; } // mismatch after j matches else if (i < N && pat[j] != txt[i]) { // Do not match lps[0..lps[j-1]] characters, // they will match anyway if (j != 0) j = lps[j - 1]; else i = i + 1; } } } int solve() { int a[3] = {0}; int n; cin >> n; string ss = "AB"; rep(i, 0, n) { string s; cin >> s; int len = s.size(); KMPSearch(ss, s); if (s[0] == 'B' && s[len - 1] != 'A') a[0]++; if (s[0] == 'B' && s[len - 1] == 'A') a[1]++; if (s[0] != 'B' && s[len - 1] == 'A') a[2]++; } if (a[2] != 0) { a[2]--; cnt += a[1]; if (a[0]) a[0]--, cnt++; if (a[0] && a[2]) cnt += min(a[0], a[1]); } else { if (a[1] != 0) { cnt += a[1] - 1; if (a[0]) cnt++; } } cout << cnt; return 0; } signed main() { int t = 1; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); clock_t time_req; // Without using pow function time_req = clock(); // cin>>t; int k = 1; while (t--) { // cout<<"case #"<<k<<":"<<" ";k++; solve(); } time_req = clock() - time_req; // cout << "Processor time taken is " // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <algorithm> #include <bits/stdc++.h> #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> using namespace std; #define int long long #define ll long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define mp make_pair #define all(a) (a).begin(), (a).end() #define FF first #define SS second #define sz(x) (int)x.size() #define endl '\n' //#define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) // mp::cpp_int #define pp pair<pii, pii> const int hell = 1000000007; int power(int a, int b) { if (b == 0) return 1; if (b == 1) return a; int t = power(a, b / 2); t %= hell; t *= t; t %= hell; if (b % 2) return (t * a) % hell; else return t; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b - a % b, a % b); } int digitsum(int x) { while (x > 9) { int ans = 0; while (x != 0) { ans += x % 10; x /= 10; } x = ans; } return x; } int pw(int a, int b) { int x = a; rep(i, 1, b) { a = a * x; } return a; } int cnt = 0; void computeLPSArray(string pat, int M, int lps[]) { int len = 0; lps[0] = 0; // lps[0] is always 0 // the loop calculates lps[i] for i = 1 to M-1 int i = 1; while (i < M) { if (pat[i] == pat[len]) { len++; lps[i] = len; i++; } else // (pat[i] != pat[len]) { // This is tricky. Consider the example. // AAACAAAA and i = 7. The idea is similar // to search step. if (len != 0) { len = lps[len - 1]; // Also, note that we do not increment // i here } else // if (len == 0) { lps[i] = 0; i++; } } } } // Prints occurrences of txt[] in pat[] void KMPSearch(string pat, string txt) { int M = pat.size(); int N = txt.size(); // create lps[] that will hold the longest prefix suffix // values for pattern int lps[M]; // Preprocess the pattern (calculate lps[] array) computeLPSArray(pat, M, lps); int i = 0; // index for txt[] int j = 0; // index for pat[] while (i < N) { if (pat[j] == txt[i]) { j++; i++; } if (j == M) { cnt++; j = lps[j - 1]; } // mismatch after j matches else if (i < N && pat[j] != txt[i]) { // Do not match lps[0..lps[j-1]] characters, // they will match anyway if (j != 0) j = lps[j - 1]; else i = i + 1; } } } int solve() { int a[3] = {0}; int n; cin >> n; string ss = "AB"; rep(i, 0, n) { string s; cin >> s; int len = s.size(); KMPSearch(ss, s); if (s[0] == 'B' && s[len - 1] != 'A') a[0]++; if (s[0] == 'B' && s[len - 1] == 'A') a[1]++; if (s[0] != 'B' && s[len - 1] == 'A') a[2]++; } if (a[2] != 0) { a[2]--; cnt += a[1]; if (a[0]) a[0]--, cnt++; if (a[0] && a[2]) cnt += min(a[0], a[2]); } else { if (a[1] != 0) { cnt += a[1] - 1; if (a[0]) cnt++; } } cout << cnt; return 0; } signed main() { int t = 1; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); clock_t time_req; // Without using pow function time_req = clock(); // cin>>t; int k = 1; while (t--) { // cout<<"case #"<<k<<":"<<" ";k++; solve(); } time_req = clock() - time_req; // cout << "Processor time taken is " // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change" ]
868,219
868,220
u240509821
cpp
p03049
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; int ans = 0; int A = 0, B = 0, BA = 0; rep(i, N) { string s; cin >> s; rep(j, s.size() - 1) if (s[j] == 'A' and s[j + 1] == 'B') ans++; if (s[0] == 'B') B++; if (s.back() == 'A') A++; if (s[0] == 'B' and s.back() == 'A') BA++; } if (B == BA and A == BA) A--; cout << ans + min(0, min(A, B)) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; int ans = 0; int A = 0, B = 0, BA = 0; rep(i, N) { string s; cin >> s; rep(j, s.size() - 1) if (s[j] == 'A' and s[j + 1] == 'B') ans++; if (s[0] == 'B') B++; if (s.back() == 'A') A++; if (s[0] == 'B' and s.back() == 'A') BA++; } if (B == BA and A == BA) A--; cout << ans + max(0, min(A, B)) << endl; return 0; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
868,221
868,222
u944316525
cpp
p03049
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; int ans = 0; int A = 0, B = 0, BA = 0; rep(i, N) { string s; cin >> s; rep(j, s.size() - 1) if (s[j] == 'A' and s[j + 1] == 'B') ans++; if (s[0] == 'B') B++; if (s.back() == 'A') A++; if (s[0] == 'B' and s.back() == 'A') BA++; } if (B == BA and A == BA) A--; cout << ans + min(A, B) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; int ans = 0; int A = 0, B = 0, BA = 0; rep(i, N) { string s; cin >> s; rep(j, s.size() - 1) if (s[j] == 'A' and s[j + 1] == 'B') ans++; if (s[0] == 'B') B++; if (s.back() == 'A') A++; if (s[0] == 'B' and s.back() == 'A') BA++; } if (B == BA and A == BA) A--; cout << ans + max(0, min(A, B)) << endl; return 0; }
[ "call.add", "call.arguments.change" ]
868,223
868,222
u944316525
cpp
p03049
#include <algorithm> #include <cstring> #include <iostream> #include <list> #include <math.h> #include <queue> #include <vector> #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; int main() { int n; cin >> n; long long ans = 0, anum = 0, bnum = 0, abnum = 0; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].length() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; } if (s[i][0] == 'B') bnum++; if (s[i][s[i].length() - 1] == 'A') anum++; if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') abnum++; } // cout << s[1][s[1].length()-1]<<endl; if (abnum == anum && abnum == bnum) ans--; cout << ans + min(anum, bnum) << endl; }
#include <algorithm> #include <cstring> #include <iostream> #include <list> #include <math.h> #include <queue> #include <vector> #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; int main() { int n; cin >> n; long long ans = 0, anum = 0, bnum = 0, abnum = 0; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].length() - 1; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++; } if (s[i][0] == 'B') bnum++; if (s[i][s[i].length() - 1] == 'A') anum++; if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') abnum++; } // cout << s[1][s[1].length()-1]<<endl; if (abnum == anum && abnum == bnum && abnum != 0) ans--; cout << ans + min(anum, bnum) << endl; }
[ "control_flow.branch.if.condition.change" ]
868,231
868,232
u461415203
cpp
p03049
#include <iostream> using namespace std; int main() { int n; cin >> n; string a[n]; int count = 0; int x = 0, y = 0; int k = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; int l = a[i].length(); for (int j = 0; j < l - 1; ++j) { if (a[i][j] == 'A' && a[i][j + 1] == 'B') { count++; } } if (a[i][l - 1] == 'A') x++; if (a[i][0] == 'B') y++; if (a[i][l - 1] == 'A' && a[i][0] == 'B') { k++; } } if (x == k && y == k) cout << k - 1 + count; else { int z = min(x, y); if (z == n) z--; cout << z + count; } }
#include <iostream> using namespace std; int main() { int n; cin >> n; string a[n]; int count = 0; int x = 0, y = 0; int k = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; int l = a[i].length(); for (int j = 0; j < l - 1; ++j) { if (a[i][j] == 'A' && a[i][j + 1] == 'B') { count++; } } if (a[i][l - 1] == 'A') x++; if (a[i][0] == 'B') y++; if (a[i][l - 1] == 'A' && a[i][0] == 'B') { k++; } } if (x == k && y == k && x != 0) cout << k - 1 + count; else { int z = min(x, y); if (z == n) z--; cout << z + count; } }
[ "control_flow.branch.if.condition.change" ]
868,233
868,234
u193815565
cpp
p03049
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n, cnt = 0, acnt = 0, bcnt = 0, both = 0; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; bool a = false; bool topb = (s[0] == 'B'); for (auto c : s) { if (a && c == 'B') cnt++; if (c == 'A') a = true; else a = false; } if (a && topb) both++; else if (a) acnt++; else if (topb) bcnt++; } // cerr << acnt << bcnt << both << cnt << '\n'; int ans; if (acnt > 0 && bcnt > 0) ans = min(acnt, bcnt) + both + cnt; else if (acnt == 0 && bcnt == 0) ans = both - 1 + cnt; else ans = both + cnt; cout << ans << '\n'; return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n, cnt = 0, acnt = 0, bcnt = 0, both = 0; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; bool a = false; bool topb = (s[0] == 'B'); for (auto c : s) { if (a && c == 'B') cnt++; if (c == 'A') a = true; else a = false; } if (a && topb) both++; else if (a) acnt++; else if (topb) bcnt++; } // cerr << acnt << bcnt << both << cnt << '\n'; int ans; if (acnt > 0 && bcnt > 0) ans = min(acnt, bcnt) + both + cnt; else if (acnt == 0 && bcnt == 0) ans = max(both - 1, 0) + cnt; else ans = both + cnt; cout << ans << '\n'; return 0; }
[ "call.add", "call.arguments.add" ]
868,235
868,236
u956758464
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { int N, numB = 0, numA = 0, numC = 0, ans = 0; bool A = false; cin >> N; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][0] == 'B') numB++; if (s[i][s[i].size() - 1] == 'A') numA++; if (s[i][0] == 'B' && s[i][s[i].size()] == 'A') numC++; } ans = min(numA, numB); for (int i = 0; i < N; i++) { for (int j = 1; j < s[i].size(); j++) { if (s[i][j] == 'B' && s[i][j - 1] == 'A') { ans++; } } } if (numA == numB && numA == numC && numA != 0) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, numB = 0, numA = 0, numC = 0, ans = 0; bool A = false; cin >> N; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; if (s[i][0] == 'B') numB++; if (s[i][s[i].size() - 1] == 'A') numA++; if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') numC++; } ans = min(numA, numB); for (int i = 0; i < N; i++) { for (int j = 1; j < s[i].size(); j++) { if (s[i][j] == 'B' && s[i][j - 1] == 'A') { ans++; } } } if (numA == numB && numA == numC && numA != 0) ans--; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
868,237
868,238
u912533549
cpp
p03049
#include <bits/stdc++.h> using namespace std; #define ll long long #define speed ios::sync_with_stdio(false) #define pb push_back #define mp make_pair #define precision(x, d) cout << fixed << setprecision(d) << x #define all(x) (x).begin(), (x).end() #define uint usigned int typedef vector<pair<char, ll>> vi; ll MOD = 1e9 + 7; // vi v1[200005],v2; // bool visit[200005]={false}; /*void bfs(ll n){ queue<ll> q; q.push(n); visit[n]=true; while(!q.empty()){ ll t=q.front(); q.pop(); v2.pb(t); for(ll i=0;i<v1[t].size();i++){ if(visit[v1[t][i]]==false){ q.push(v1[t][i]); visit[v1[t][i]]=true; } } } }*/ /*void dfs(ll n){ for(ll i=0;i<v1[n].size();i++) { ll y=v1[n][i]; if(visit[y]==0) { v2.pb(y); visit[y]=1; dfs(y); } } }*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, i, h, j, r, c1 = 0, c2 = 0, ans, error = 0; cin >> n; string s[n]; for (i = 0; i < n; i++) { cin >> s[i]; j = s[i].length(); if (s[i][0] == 'B') c1++; if (s[i][j - 1] == 'A') c2++; if (s[i][0] == 'B' && s[i][j - 1] == 'A') error++; } ans = min(c1, c2); if (error == c1 && c1 == c2) ans--; for (i = 0; i < n; i++) { j = s[i].length(); for (r = 0; r < j - 1; r++) { if (s[i][r] == 'A' && s[i][r + 1] == 'B') ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define speed ios::sync_with_stdio(false) #define pb push_back #define mp make_pair #define precision(x, d) cout << fixed << setprecision(d) << x #define all(x) (x).begin(), (x).end() #define uint usigned int typedef vector<pair<char, ll>> vi; ll MOD = 1e9 + 7; // vi v1[200005],v2; // bool visit[200005]={false}; /*void bfs(ll n){ queue<ll> q; q.push(n); visit[n]=true; while(!q.empty()){ ll t=q.front(); q.pop(); v2.pb(t); for(ll i=0;i<v1[t].size();i++){ if(visit[v1[t][i]]==false){ q.push(v1[t][i]); visit[v1[t][i]]=true; } } } }*/ /*void dfs(ll n){ for(ll i=0;i<v1[n].size();i++) { ll y=v1[n][i]; if(visit[y]==0) { v2.pb(y); visit[y]=1; dfs(y); } } }*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, i, h, j, r, c1 = 0, c2 = 0, ans, error = 0; cin >> n; string s[n]; for (i = 0; i < n; i++) { cin >> s[i]; j = s[i].length(); if (s[i][0] == 'B') c1++; if (s[i][j - 1] == 'A') c2++; if (s[i][0] == 'B' && s[i][j - 1] == 'A') error++; } ans = min(c1, c2); if (error == c1 && c1 == c2 && error != 0) ans--; for (i = 0; i < n; i++) { j = s[i].length(); for (r = 0; r < j - 1; r++) { if (s[i][r] == 'A' && s[i][r + 1] == 'B') ans++; } } cout << ans; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,245
868,246
u415518175
cpp
p03049
#include <bits/stdc++.h> #define INF 1e9 using namespace std; int main() { int N; cin >> N; int AB = 0; int A_end = 0; int B_start = 0; int same = 0; string S = "AB"; vector<string> s(N); for (int i = 0; i < N; ++i) { bool same_flg = false; cin >> s[i]; for (int j = 0; j < s[i].size() - S.size() + 1; ++j) { if (s[i].substr(j, S.size()) == S) { ++AB; } } if (s[i].find_last_of('A') == s[i].size() - 1) { ++A_end; same_flg = true; } if (s[i].find_first_of('B') == 0) { ++B_start; if (same_flg) { ++same; } } } if (A_end == B_start && B_start == same) { cout << AB + same - 1 << endl; } else { cout << AB + min(A_end, B_start) << endl; } }
#include <bits/stdc++.h> #define INF 1e9 using namespace std; int main() { int N; cin >> N; int AB = 0; int A_end = 0; int B_start = 0; int same = 0; string S = "AB"; vector<string> s(N); for (int i = 0; i < N; ++i) { bool same_flg = false; cin >> s[i]; for (int j = 0; j < s[i].size() - S.size() + 1; ++j) { if (s[i].substr(j, S.size()) == S) { ++AB; } } if (s[i].find_last_of('A') == s[i].size() - 1) { ++A_end; same_flg = true; } if (s[i].find_first_of('B') == 0) { ++B_start; if (same_flg) { ++same; } } } if (A_end > 0 && A_end == B_start && B_start == same) { cout << AB + same - 1 << endl; } else { cout << AB + min(A_end, B_start) << endl; } }
[ "control_flow.branch.if.condition.change" ]
868,247
868,248
u701556979
cpp
p03049
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[10000]; int aa = 0; int bb = 0; int ab = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; int ss = s[i].size(); if (s[i][0] == 'B') { bb++; } if (s[i][ss - 1] == 'A') { aa++; } if (s[i][0] == 'B' && s[i][ss - 1] == 'A') { ba++; } for (int j = 0; j < ss; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ab++; } } } if (n == 1) { cout << ab << endl; } else if (ba == aa && aa == bb && bb == 0) { cout << 0 << endl; } else if (ba == aa && aa == bb) { cout << ab + aa - 1 << endl; } else { cout << ab + min(aa, bb) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[10000]; int aa = 0; int bb = 0; int ab = 0; int ba = 0; for (int i = 0; i < n; i++) { cin >> s[i]; int ss = s[i].size(); if (s[i][0] == 'B') { bb++; } if (s[i][ss - 1] == 'A') { aa++; } if (s[i][0] == 'B' && s[i][ss - 1] == 'A') { ba++; } for (int j = 0; j < ss; j++) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ab++; } } } if (n == 1) { cout << ab << endl; } else if (ba == aa && aa == bb && bb == 0) { cout << ab << endl; } else if (ba == aa && aa == bb) { cout << ab + aa - 1 << endl; } else { cout << ab + min(aa, bb) << endl; } }
[ "identifier.replace.add", "literal.replace.remove", "io.output.change" ]
868,249
868,250
u922602011
cpp
p03049
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/timeb.h> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define reprev(i, n) reprrev(i, 0, n) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define chmin(mi, val) mi = min(mi, val) #define chmax(ma, val) ma = max(ma, val) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mp make_pair #define mt make_tuple #define INF 1050000000 #define INFR INT_MAX #define INFL (long long)(4e18) #define INFLR LLONG_MAX #define EPS (1e-10) #define MOD 1000000007 // #define MOD 998244353 #define PI 3.141592653589793238 #define RMAX 4294967295 using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vvs = vector<vector<string>>; using Pi = pair<int, int>; using vPi = vector<Pi>; using vvPi = vector<vector<Pi>>; using vvvPi = vector<vector<vector<Pi>>>; using vvvvPi = vector<vector<vector<vector<Pi>>>>; using Pll = pair<ll, ll>; using vPll = vector<Pll>; using Pd = pair<double, double>; using vPd = vector<Pd>; template <class T> using vec = vector<T>; template <class T> using pql = priority_queue<T, vector<T>, greater<T>>; // vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif // ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^ string YN(bool y, int id = 0) { if (id) cout << id; return (y ? "YES" : "NO"); } string yn(bool y, int id = 0) { if (id) cout << id; return (y ? "Yes" : "No"); } string ON(bool y, int id = 0) { if (id) cout << id; return (y ? "OK" : "NG"); } int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}}; int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; char dirchar[4] = {'<', '^', '>', 'v'}; // [a,b) int irand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<int> dist(a, b - 1); return dist(Rand); } // [a,b) double drand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_real_distribution<double> dist(a, b); return dist(Rand); } // https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c template <typename A, typename F> inline auto transform(const A &v, F &&f) { using result_type = decltype(std::declval<F>()(std::declval<typename A::value_type>())); vector<result_type> y(v.size()); std::transform(std::cbegin(v), std::cend(v), std::begin(y), f); return y; } // 多次元vector生成 template <class T> vector<T> make_v(size_t size, const T &init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <typename T> T max(vector<T> a) { return *max_element(all(a)); } template <typename T> T min(vector<T> a) { return *min_element(all(a)); } template <typename T> T sum(vector<T> a) { return accumulate(all(a), (T)0); } // mapでカウントとかする template <typename T> void add(map<T, int> &m, T item) { if (m.find(item) == m.end()) { m[item] = 1; } else { m[item]++; } } // デフォルト値つきのmapのget template <typename T, typename U> U get(map<T, U> m, T key, U def) { if (m.find(key) == m.end()) { return def; } else { return m[key]; } } template <typename T> bool contains(set<T> t, const T &key) { return t.find(key) != t.end(); } template <typename T, typename U> bool contains(map<T, U> t, const T &key) { return t.find(key) != t.end(); } template <class T> struct Edge { int from, to; T cost; bool operator<(Edge e) { return cost < e.cost; } }; template <class T> using Graph = vec<vec<Edge<T>>>; template <class T> ostream &operator<<(ostream &os, Edge<T> &edge) { os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")"; return os; } //====================================================== int main(void) { int N; cin >> N; vs s(N); cin >> s; int ans = 0; int a = 0, b = 0, ba = 0; rep(i, N) { rep(j, s.size() - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; } } if (s[i][0] == 'B') { if (s[i].back() == 'A') { ba++; } else { b++; } } else if (s[i].back() == 'A') { a++; } } dump(ans, ba, a, b); if (a == 0) { if (ba > 0) { ans += ba - 1; if (b > 0) ans++; } } else { // a > 0 if (ba == 0) { ans += min(a, b); } else { // ba > 0 if (b == 0) { ans += ba; } else { // 全部ある ans += ba + 1 + min(a - 1, b - 1); } } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/timeb.h> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define reprev(i, n) reprrev(i, 0, n) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define chmin(mi, val) mi = min(mi, val) #define chmax(ma, val) ma = max(ma, val) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mp make_pair #define mt make_tuple #define INF 1050000000 #define INFR INT_MAX #define INFL (long long)(4e18) #define INFLR LLONG_MAX #define EPS (1e-10) #define MOD 1000000007 // #define MOD 998244353 #define PI 3.141592653589793238 #define RMAX 4294967295 using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vvs = vector<vector<string>>; using Pi = pair<int, int>; using vPi = vector<Pi>; using vvPi = vector<vector<Pi>>; using vvvPi = vector<vector<vector<Pi>>>; using vvvvPi = vector<vector<vector<vector<Pi>>>>; using Pll = pair<ll, ll>; using vPll = vector<Pll>; using Pd = pair<double, double>; using vPd = vector<Pd>; template <class T> using vec = vector<T>; template <class T> using pql = priority_queue<T, vector<T>, greater<T>>; // vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif // ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^ string YN(bool y, int id = 0) { if (id) cout << id; return (y ? "YES" : "NO"); } string yn(bool y, int id = 0) { if (id) cout << id; return (y ? "Yes" : "No"); } string ON(bool y, int id = 0) { if (id) cout << id; return (y ? "OK" : "NG"); } int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}}; int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; char dirchar[4] = {'<', '^', '>', 'v'}; // [a,b) int irand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<int> dist(a, b - 1); return dist(Rand); } // [a,b) double drand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_real_distribution<double> dist(a, b); return dist(Rand); } // https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c template <typename A, typename F> inline auto transform(const A &v, F &&f) { using result_type = decltype(std::declval<F>()(std::declval<typename A::value_type>())); vector<result_type> y(v.size()); std::transform(std::cbegin(v), std::cend(v), std::begin(y), f); return y; } // 多次元vector生成 template <class T> vector<T> make_v(size_t size, const T &init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <typename T> T max(vector<T> a) { return *max_element(all(a)); } template <typename T> T min(vector<T> a) { return *min_element(all(a)); } template <typename T> T sum(vector<T> a) { return accumulate(all(a), (T)0); } // mapでカウントとかする template <typename T> void add(map<T, int> &m, T item) { if (m.find(item) == m.end()) { m[item] = 1; } else { m[item]++; } } // デフォルト値つきのmapのget template <typename T, typename U> U get(map<T, U> m, T key, U def) { if (m.find(key) == m.end()) { return def; } else { return m[key]; } } template <typename T> bool contains(set<T> t, const T &key) { return t.find(key) != t.end(); } template <typename T, typename U> bool contains(map<T, U> t, const T &key) { return t.find(key) != t.end(); } template <class T> struct Edge { int from, to; T cost; bool operator<(Edge e) { return cost < e.cost; } }; template <class T> using Graph = vec<vec<Edge<T>>>; template <class T> ostream &operator<<(ostream &os, Edge<T> &edge) { os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")"; return os; } //====================================================== int main(void) { int N; cin >> N; vs s(N); cin >> s; int ans = 0; int a = 0, b = 0, ba = 0; rep(i, N) { rep(j, s[i].size() - 1) { if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; } } if (s[i][0] == 'B') { if (s[i].back() == 'A') { ba++; } else { b++; } } else if (s[i].back() == 'A') { a++; } } dump(ans, ba, a, b); if (a == 0) { if (ba > 0) { ans += ba - 1; if (b > 0) ans++; } } else { // a > 0 if (ba == 0) { ans += min(a, b); } else { // ba > 0 if (b == 0) { ans += ba; } else { // 全部ある ans += ba + 1 + min(a - 1, b - 1); } } } cout << ans << endl; return 0; }
[]
868,258
868,259
u366676780
cpp
p03049
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <cstring> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; signed main() { int N; cin >> N; vector<string> strs(N); for (int i = 0; i < N; i++) cin >> strs[i]; int a = 0; int b = 0; int B_start = 0; int A_end = 0; for (string str : strs) { if (str[0] == 'B' && str[str.size() - 1] != 'A') B_start++; if (str[str.size() - 1] == 'A' && str[0] != 'B') A_end++; if (str[0] == 'B' && str[str.size() - 1] == 'A') a++; for (int i = 0; i < str.size() - 1; i++) { if (str[i] == 'A' && str[i + 1] == 'B') b++; } } if (A_end + B_start > 0) { cout << a + b + min(A_end, B_start) << endl; } else { cout << b + (a - 1) << endl; } // cout << max(0LL, a - 1) + b + min(A_end, B_start) + (A_end != B_start && a // > 0 ? 1 : 0) << endl; return 0; }
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <cstring> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; signed main() { int N; cin >> N; vector<string> strs(N); for (int i = 0; i < N; i++) cin >> strs[i]; int a = 0; int b = 0; int B_start = 0; int A_end = 0; for (string str : strs) { if (str[0] == 'B' && str[str.size() - 1] != 'A') B_start++; if (str[str.size() - 1] == 'A' && str[0] != 'B') A_end++; if (str[0] == 'B' && str[str.size() - 1] == 'A') a++; for (int i = 0; i < str.size() - 1; i++) { if (str[i] == 'A' && str[i + 1] == 'B') b++; } } if (A_end + B_start > 0) { cout << a + b + min(A_end, B_start) << endl; } else { cout << b + max(0LL, a - 1) << endl; } // cout << max(0LL, a - 1) + b + min(A_end, B_start) + (A_end != B_start && a // > 0 ? 1 : 0) << endl; return 0; }
[ "call.add", "call.arguments.add" ]
868,260
868,261
u853132965
cpp
p03049
#include <cstdio> #include <cstring> #include <algorithm> using std::max; using std::min; int countAB(char *s) { int i, res = 0; for (i = 0; s[i + 1]; i++) { if (s[i] == 'A' && s[i + 1] == 'B') res += 1; } return res; } int main(void) { int i, N, tailA = 0, headB = 0, res, tailHeadAB = 0; char msg[13]; scanf("%d", &N); res = 0; for (i = 0; i < N; i++) { scanf("%s", msg); res += countAB(msg); if (msg[strlen(msg) - 1] == 'A' && msg[0] == 'B') tailHeadAB += 1; else { if (msg[0] == 'B') { headB += 1; } else if (msg[strlen(msg) - 1] == 'A') { tailA += 1; } } } if (tailA > 0) { tailHeadAB += 1; tailA -= 1; } if (headB > 0) { tailHeadAB += 1; headB -= 1; } printf("%d\n", res + (tailHeadAB - 1) + max(0, min(tailA, headB))); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> using std::max; using std::min; int countAB(char *s) { int i, res = 0; for (i = 0; s[i + 1]; i++) { if (s[i] == 'A' && s[i + 1] == 'B') res += 1; } return res; } int main(void) { int i, N, tailA = 0, headB = 0, res, tailHeadAB = 0; char msg[13]; scanf("%d", &N); res = 0; for (i = 0; i < N; i++) { scanf("%s", msg); res += countAB(msg); if (msg[strlen(msg) - 1] == 'A' && msg[0] == 'B') tailHeadAB += 1; else { if (msg[0] == 'B') { headB += 1; } else if (msg[strlen(msg) - 1] == 'A') { tailA += 1; } } // printf("%d\t%d\t%d\t%d\n",res,tailA,headB,tailHeadAB); } if (tailA > 0) { tailHeadAB += 1; tailA -= 1; } if (headB > 0) { tailHeadAB += 1; headB -= 1; } printf("%d\n", res + max(0, (tailHeadAB - 1)) + max(0, min(tailA, headB))); return 0; }
[ "call.add", "call.arguments.change" ]
868,262
868,263
u643081547
cpp
p03049
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int ans = 0, N; cin >> N; vector<string> S(N); vector<string> AB; int acnt = 0, bcnt = 0, abcnt = 0; for (int i = 0; i < N; i++) { cin >> S[i]; for (int l = 0; l < S[i].size() - 1; l++) { if (S[i][l] == 'A' && S[i][l + 1] == 'B') ans += 1; } if (S[i][S[i].size() - 1] == 'A' && S[i][0] == 'B') { abcnt++; } else if (S[i][0] == 'B') { bcnt++; } else if (S[i][S[i].size() - 1] == 'A') { acnt++; } } if (acnt == 0 && bcnt == 0) { ans--; } acnt += abcnt; bcnt += abcnt; ans += min(acnt, bcnt); cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int ans = 0, N; cin >> N; vector<string> S(N); vector<string> AB; int acnt = 0, bcnt = 0, abcnt = 0; for (int i = 0; i < N; i++) { cin >> S[i]; for (int l = 0; l < S[i].size() - 1; l++) { if (S[i][l] == 'A' && S[i][l + 1] == 'B') ans += 1; } if (S[i][S[i].size() - 1] == 'A' && S[i][0] == 'B') { abcnt++; } else if (S[i][0] == 'B') { bcnt++; } else if (S[i][S[i].size() - 1] == 'A') { acnt++; } } if (acnt == 0 && bcnt == 0 && abcnt > 0) { ans--; } acnt += abcnt; bcnt += abcnt; ans += min(acnt, bcnt); cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
868,266
868,267
u982721500
cpp
p03049
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define FOR(i, x, y) for (ll i = x; i < y; i++) typedef long long ll; using namespace std; deque<string> end_b, reg; ll ans = 0, indx = 0; void iter(string i) { FOR(j, 0, i.size() - 1) if (i[j] == 'A' && i[j + 1] == 'B') ans++; if (i.back() == 'A' && indx < end_b.size()) { ans++; iter(end_b[indx++]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; FOR(i, 0, n) { string s; cin >> s; if (s[0] == 'B') { if (s.back() == 'A') end_b.push_front(s); else end_b.push_back(s); } else { if (s.back() == 'A') reg.push_front(s); else reg.push_back(s); } } for (auto &i : reg) iter(i); for (; indx < end_b.size(); indx++) iter(end_b[indx]); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define FOR(i, x, y) for (ll i = x; i < y; i++) typedef long long ll; using namespace std; deque<string> end_b, reg; ll ans = 0, indx = 0; void iter(string i) { // cout << i << ' ' << indx << endl; FOR(j, 0, i.size() - 1) if (i[j] == 'A' && i[j + 1] == 'B') ans++; if (i.back() == 'A' && indx < end_b.size()) { ans++; iter(end_b[indx++]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; FOR(i, 0, n) { string s; cin >> s; if (s[0] == 'B') { if (s.back() == 'A') end_b.push_front(s); else end_b.push_back(s); } else { if (s.back() == 'A') reg.push_front(s); else reg.push_back(s); } } for (auto &i : reg) iter(i); for (; indx < end_b.size();) iter(end_b[indx++]); cout << ans << '\n'; return 0; }
[ "control_flow.loop.for.update.change", "call.arguments.change" ]
868,268
868,269
u290148197
cpp
p03049
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <stdexcept> using namespace std; // conversion //------------------------------------------ inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (l" << __line__ << ")" \ << " " << __file__ << endl // type alias using ll = long long; using ull = unsigned long long; // constant value const ll mod = 1000000007ll; template <class ll> inline ll getCeilExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; --a; for (; a != 0; a >>= 1) { ++index; } return index; } template <class ll> inline ll getFloorExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; a >>= 1; for (; a != 0; a >>= 1) { ++index; } return index; } // computational complexity: o(log(max(a, b))) template <class ll> inline ll getGcd(ll a, ll b) { if (b == 0) { return a; } return getGcd(b, a % b); } // computational complexity: o(log(max(a, b))) template <class ll> inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b) { if (b == 0) { return {1, 0}; } auto sol = getBezoutsIdentitySolution(b, a % b); return {sol.second, sol.first - (a / b) * sol.second}; } inline ll getModValue(ll a, ll m) { return (a % m + m) % m; } // computational complexity: o(log(max(a, n))) inline ll getModInverse(ll a, ll m) { auto sol = getBezoutsIdentitySolution(a, m); if (a * sol.first + m * sol.second != 1) { return -1; } return getModValue(sol.first, m); } ll getModPower(ll base, unsigned t, ll m) { if (t == 0) { return 1ll; } auto res = getModPower(base, t >> 1, m); res = getModValue(res * res, m); if (t % 2 == 1) { res = getModValue(res * base, m); } return res; } class ModCombCalculator { private: ll n_; ll mod_; vector<ll> values_; public: ModCombCalculator(ll n, ll mod) : n_(n), values_(n + 1LL, -1LL), mod_(mod) { values_[0] = 1LL; } ll calculate(ll r) { if (r < 0LL || n_ < r) { return 0LL; } if (values_[r] != -1) { return values_[r]; } ll res; if (values_[r - 1] != -1) { res = values_[r - 1]; } else { res = calculate(r - 1); } values_[r] = getModValue( getModValue(res * (n_ - r + 1LL), mod_) * getModInverse(r, mod_), mod_); return values_[r]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll res = 0; ll both_ab = 0; ll only_a = 0; ll only_b = 0; vector<string> strs(n); for (ll i = 0; i < n; ++i) { cin >> strs[i]; if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] == 'A') { ++both_ab; } else if (strs[i][0] != 'B' && strs[i][strs[i].size() - 1] == 'A') { ++only_a; } else if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] != 'A') { ++only_b; } for (ll j = 0; j + 1 < strs[i].size(); ++j) { if (strs[i][j] == 'A' && strs[i][j + 1] == 'B') { ++res; } } } if (only_a == 0 && only_b == 0) { res += min(both_ab - 1, 0LL); } else { res += min(only_a + both_ab, only_b + both_ab); } cout << res << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <stdexcept> using namespace std; // conversion //------------------------------------------ inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (l" << __line__ << ")" \ << " " << __file__ << endl // type alias using ll = long long; using ull = unsigned long long; // constant value const ll mod = 1000000007ll; template <class ll> inline ll getCeilExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; --a; for (; a != 0; a >>= 1) { ++index; } return index; } template <class ll> inline ll getFloorExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; a >>= 1; for (; a != 0; a >>= 1) { ++index; } return index; } // computational complexity: o(log(max(a, b))) template <class ll> inline ll getGcd(ll a, ll b) { if (b == 0) { return a; } return getGcd(b, a % b); } // computational complexity: o(log(max(a, b))) template <class ll> inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b) { if (b == 0) { return {1, 0}; } auto sol = getBezoutsIdentitySolution(b, a % b); return {sol.second, sol.first - (a / b) * sol.second}; } inline ll getModValue(ll a, ll m) { return (a % m + m) % m; } // computational complexity: o(log(max(a, n))) inline ll getModInverse(ll a, ll m) { auto sol = getBezoutsIdentitySolution(a, m); if (a * sol.first + m * sol.second != 1) { return -1; } return getModValue(sol.first, m); } ll getModPower(ll base, unsigned t, ll m) { if (t == 0) { return 1ll; } auto res = getModPower(base, t >> 1, m); res = getModValue(res * res, m); if (t % 2 == 1) { res = getModValue(res * base, m); } return res; } class ModCombCalculator { private: ll n_; ll mod_; vector<ll> values_; public: ModCombCalculator(ll n, ll mod) : n_(n), values_(n + 1LL, -1LL), mod_(mod) { values_[0] = 1LL; } ll calculate(ll r) { if (r < 0LL || n_ < r) { return 0LL; } if (values_[r] != -1) { return values_[r]; } ll res; if (values_[r - 1] != -1) { res = values_[r - 1]; } else { res = calculate(r - 1); } values_[r] = getModValue( getModValue(res * (n_ - r + 1LL), mod_) * getModInverse(r, mod_), mod_); return values_[r]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll res = 0; ll both_ab = 0; ll only_a = 0; ll only_b = 0; vector<string> strs(n); for (ll i = 0; i < n; ++i) { cin >> strs[i]; if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] == 'A') { ++both_ab; } else if (strs[i][0] != 'B' && strs[i][strs[i].size() - 1] == 'A') { ++only_a; } else if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] != 'A') { ++only_b; } for (ll j = 0; j + 1 < strs[i].size(); ++j) { if (strs[i][j] == 'A' && strs[i][j + 1] == 'B') { ++res; } } } if (only_a == 0 && only_b == 0) { res += max(both_ab - 1, 0LL); } else { res += min(only_a + both_ab, only_b + both_ab); } cout << res << endl; return 0; }
[ "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
868,272
868,273
u331542638
cpp
p03049
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <stdexcept> using namespace std; // conversion //------------------------------------------ inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (l" << __line__ << ")" \ << " " << __file__ << endl // type alias using ll = long long; using ull = unsigned long long; // constant value const ll mod = 1000000007ll; template <class ll> inline ll getCeilExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; --a; for (; a != 0; a >>= 1) { ++index; } return index; } template <class ll> inline ll getFloorExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; a >>= 1; for (; a != 0; a >>= 1) { ++index; } return index; } // computational complexity: o(log(max(a, b))) template <class ll> inline ll getGcd(ll a, ll b) { if (b == 0) { return a; } return getGcd(b, a % b); } // computational complexity: o(log(max(a, b))) template <class ll> inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b) { if (b == 0) { return {1, 0}; } auto sol = getBezoutsIdentitySolution(b, a % b); return {sol.second, sol.first - (a / b) * sol.second}; } inline ll getModValue(ll a, ll m) { return (a % m + m) % m; } // computational complexity: o(log(max(a, n))) inline ll getModInverse(ll a, ll m) { auto sol = getBezoutsIdentitySolution(a, m); if (a * sol.first + m * sol.second != 1) { return -1; } return getModValue(sol.first, m); } ll getModPower(ll base, unsigned t, ll m) { if (t == 0) { return 1ll; } auto res = getModPower(base, t >> 1, m); res = getModValue(res * res, m); if (t % 2 == 1) { res = getModValue(res * base, m); } return res; } class ModCombCalculator { private: ll n_; ll mod_; vector<ll> values_; public: ModCombCalculator(ll n, ll mod) : n_(n), values_(n + 1LL, -1LL), mod_(mod) { values_[0] = 1LL; } ll calculate(ll r) { if (r < 0LL || n_ < r) { return 0LL; } if (values_[r] != -1) { return values_[r]; } ll res; if (values_[r - 1] != -1) { res = values_[r - 1]; } else { res = calculate(r - 1); } values_[r] = getModValue( getModValue(res * (n_ - r + 1LL), mod_) * getModInverse(r, mod_), mod_); return values_[r]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll res = 0; ll both_ab = 0; ll only_a = 0; ll only_b = 0; vector<string> strs(n); for (ll i = 0; i < n; ++i) { cin >> strs[i]; if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] == 'A') { ++both_ab; } else if (strs[i][0] != 'B' && strs[i][strs[i].size() - 1] == 'A') { ++only_a; } else if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] != 'A') { ++only_b; } for (ll j = 0; j + 1 < strs[i].size(); ++j) { if (strs[i][j] == 'A' && strs[i][j + 1] == 'B') { ++res; } } } if (only_a == 0 && only_b == 0) { res += both_ab - 1; } else { res += min(only_a + both_ab, only_b + both_ab); } cout << res << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <stdexcept> using namespace std; // conversion //------------------------------------------ inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (l" << __line__ << ")" \ << " " << __file__ << endl // type alias using ll = long long; using ull = unsigned long long; // constant value const ll mod = 1000000007ll; template <class ll> inline ll getCeilExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; --a; for (; a != 0; a >>= 1) { ++index; } return index; } template <class ll> inline ll getFloorExponent(ll a) { if (a <= 0) { throw invalid_argument("vaule equal to or less than 0 should not be valid"); } ll index = 0; a >>= 1; for (; a != 0; a >>= 1) { ++index; } return index; } // computational complexity: o(log(max(a, b))) template <class ll> inline ll getGcd(ll a, ll b) { if (b == 0) { return a; } return getGcd(b, a % b); } // computational complexity: o(log(max(a, b))) template <class ll> inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b) { if (b == 0) { return {1, 0}; } auto sol = getBezoutsIdentitySolution(b, a % b); return {sol.second, sol.first - (a / b) * sol.second}; } inline ll getModValue(ll a, ll m) { return (a % m + m) % m; } // computational complexity: o(log(max(a, n))) inline ll getModInverse(ll a, ll m) { auto sol = getBezoutsIdentitySolution(a, m); if (a * sol.first + m * sol.second != 1) { return -1; } return getModValue(sol.first, m); } ll getModPower(ll base, unsigned t, ll m) { if (t == 0) { return 1ll; } auto res = getModPower(base, t >> 1, m); res = getModValue(res * res, m); if (t % 2 == 1) { res = getModValue(res * base, m); } return res; } class ModCombCalculator { private: ll n_; ll mod_; vector<ll> values_; public: ModCombCalculator(ll n, ll mod) : n_(n), values_(n + 1LL, -1LL), mod_(mod) { values_[0] = 1LL; } ll calculate(ll r) { if (r < 0LL || n_ < r) { return 0LL; } if (values_[r] != -1) { return values_[r]; } ll res; if (values_[r - 1] != -1) { res = values_[r - 1]; } else { res = calculate(r - 1); } values_[r] = getModValue( getModValue(res * (n_ - r + 1LL), mod_) * getModInverse(r, mod_), mod_); return values_[r]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll res = 0; ll both_ab = 0; ll only_a = 0; ll only_b = 0; vector<string> strs(n); for (ll i = 0; i < n; ++i) { cin >> strs[i]; if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] == 'A') { ++both_ab; } else if (strs[i][0] != 'B' && strs[i][strs[i].size() - 1] == 'A') { ++only_a; } else if (strs[i][0] == 'B' && strs[i][strs[i].size() - 1] != 'A') { ++only_b; } for (ll j = 0; j + 1 < strs[i].size(); ++j) { if (strs[i][j] == 'A' && strs[i][j + 1] == 'B') { ++res; } } } if (only_a == 0 && only_b == 0) { res += max(both_ab - 1, 0LL); } else { res += min(only_a + both_ab, only_b + both_ab); } cout << res << endl; return 0; }
[ "call.add", "call.arguments.add" ]
868,274
868,273
u331542638
cpp
p03049
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define INF 100000000000 #define MOD 1000000007 #define ll long long int using namespace std; int cntAB(string s, int l, int r) { // [l,r] int res = 0; for (int i = l; i < r; i++) { if (s[i] == 'A' and s[i + 1] == 'B') { res++; i++; continue; } } // cout<<res<<endl; return res; } int main() { int N; cin >> N; int XA = 0, BY = 0, BA = 0; int ans = 0; int midAB = 0; int leftB = 0; int rightA = 0; vector<string> S; S.resize(N); for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { string now = S[i]; int l = 0, r = now.size() - 1; if (now[0] == 'B' and now[r] == 'A') BA++; else if (now[0] == 'B') BY++; else if (now[r] == 'A') XA++; if (now[0] == 'B') { leftB++; l++; } if (now[r] == 'A') { rightA++; r--; } ans += cntAB(now, l, r); } if (XA >= 1 and BY >= 1) { ans += BA + 1; ans += min(XA - 1, BY - 1); } else if (XA >= 1 or BY >= 1) ans += BA; else ans += BA - 1; cout << ans << endl; /* cout<<XA<<endl; cout<<BY<<endl; cout<<BA<<endl; */ return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define INF 100000000000 #define MOD 1000000007 #define ll long long int using namespace std; int cntAB(string s, int l, int r) { // [l,r] int res = 0; for (int i = l; i < r; i++) { if (s[i] == 'A' and s[i + 1] == 'B') { res++; i++; continue; } } // cout<<res<<endl; return res; } int main() { int N; cin >> N; int XA = 0, BY = 0, BA = 0; int ans = 0; int midAB = 0; int leftB = 0; int rightA = 0; vector<string> S; S.resize(N); for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { string now = S[i]; int l = 0, r = now.size() - 1; if (now[0] == 'B' and now[r] == 'A') BA++; else if (now[0] == 'B') BY++; else if (now[r] == 'A') XA++; if (now[0] == 'B') { leftB++; l++; } if (now[r] == 'A') { rightA++; r--; } ans += cntAB(now, l, r); } if (XA >= 1 and BY >= 1) { ans += BA + 1; ans += min(XA - 1, BY - 1); } else if (XA >= 1 or BY >= 1) ans += BA; else if (BA > 0) ans += BA - 1; cout << ans << endl; /* cout<<XA<<endl; cout<<BY<<endl; cout<<BA<<endl; */ return 0; }
[ "control_flow.branch.if.add" ]
868,281
868,282
u617525345
cpp
p03049
#include <bits/stdc++.h> using namespace std; int find(const string &word) { int count = 0; for (string::size_type pos = 0; (pos = word.find("AB", pos)) != string::npos; pos += 1) { ++count; } return count; } int main() { int N; cin >> N; string s[N]; for (int i = 0; i < N; i++) cin >> s[i]; int ans = 0; int a = 0, b = 0, ba = 0; for (int i = 0; i < N; i++) { ans += find(s[i]); if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') { a++; b++; ba++; } else if (s[i][0] == 'B') b++; else if (s[i][s[i].size() - 1] == 'A') a++; } ans += min(a, b); if (max(a, b) == ba) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int find(const string &word) { int count = 0; for (string::size_type pos = 0; (pos = word.find("AB", pos)) != string::npos; pos += 1) { ++count; } return count; } int main() { int N; cin >> N; string s[N]; for (int i = 0; i < N; i++) cin >> s[i]; int ans = 0; int a = 0, b = 0, ba = 0; for (int i = 0; i < N; i++) { ans += find(s[i]); if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') { a++; b++; ba++; } else if (s[i][0] == 'B') b++; else if (s[i][s[i].size() - 1] == 'A') a++; } ans += min(a, b); if (max(a, b) == ba && ba != 0) ans--; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
868,283
868,284
u917212538
cpp
p03049
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define vi vector<int> #define pii pair<int, int> #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define SZ(x) (int)(x.size()) #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define inf 1000000007 #define mod 1000000007 #define x first #define y second #define pi acos(-1.0) #define DBG(x) cerr << (#x) << "=" << x << "\n"; //#define dprintf(...) #define hash _hash //#define dprintf(...) fprintf(outFile,__VA_ARGS__) #define FOREACH(it, x) \ for (__typeof(x.begin()) it = x.begin(); it != x.end(); it++) #define ull unsigned long long #define ll long long #define N 2000010 template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } // FILE* outFile; inline void add(int &a, int b) { a += b; while (a >= mod) a -= mod; } int pow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = ans * (ll)a % mod; a = (ll)a * a % mod; b >>= 1; } return ans; } int main() { int j, k, i, T, ca = 0, n, K = 0, m; scanf("%d", &n); int ans = 0, a = 0, b = 0, c = 0; char s[12]; rep(i, 0, n) { scanf("%s", s); m = strlen(s); rep(j, 0, m - 1) { if (s[j] == 'A' && s[j + 1] == 'B') ans++; } if (s[0] == 'B' && s[m - 1] == 'A') c++; else if (s[0] == 'B') b++; else if (s[m - 1] == 'A') a++; } // cerr << a << " " << b << " " << c <<"\n"; if (a || b) ans += c + min(a, b); else { ans += c - 1; } printf("%d\n", ans); return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define vi vector<int> #define pii pair<int, int> #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define SZ(x) (int)(x.size()) #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define inf 1000000007 #define mod 1000000007 #define x first #define y second #define pi acos(-1.0) #define DBG(x) cerr << (#x) << "=" << x << "\n"; //#define dprintf(...) #define hash _hash //#define dprintf(...) fprintf(outFile,__VA_ARGS__) #define FOREACH(it, x) \ for (__typeof(x.begin()) it = x.begin(); it != x.end(); it++) #define ull unsigned long long #define ll long long #define N 2000010 template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } // FILE* outFile; inline void add(int &a, int b) { a += b; while (a >= mod) a -= mod; } int pow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = ans * (ll)a % mod; a = (ll)a * a % mod; b >>= 1; } return ans; } int main() { int j, k, i, T, ca = 0, n, K = 0, m; scanf("%d", &n); int ans = 0, a = 0, b = 0, c = 0; char s[12]; rep(i, 0, n) { scanf("%s", s); m = strlen(s); rep(j, 0, m - 1) { if (s[j] == 'A' && s[j + 1] == 'B') ans++; } if (s[0] == 'B' && s[m - 1] == 'A') c++; else if (s[0] == 'B') b++; else if (s[m - 1] == 'A') a++; } // cerr << a << " " << b << " " << c <<"\n"; if (a || b) ans += c + min(a, b); else if (c) { ans += c - 1; } printf("%d\n", ans); return 0; }
[ "control_flow.branch.if.add" ]
868,287
868,288
u298360432
cpp
p03049
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define sz(c) (static_cast<int>(c.size())) #define endl "\n" #ifdef DEBUG #define dump(v) cerr << "[" #v << ":" << (v) << "]" << endl; #else #define dump(v) #endif typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; const ll MOD = (1e9 + 7); const ll INF = (1e9 + 123456789); const ll INFL = (INF * INF); inline ll addm(ll a, ll b, ll m = MOD) { return ((a + b) % m); } inline ll subm(ll a, ll b, ll m = MOD) { return (((a - b) % m + m) % m); } inline ll mulm(ll a, ll b, ll m = MOD) { return ((a * b) % m); } ll powm(ll a, ll b, ll m = MOD) { ll ret = (!b) ? 1 : powm(a, b / 2, m); return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m); } ll inv(ll x, ll m = MOD) { return powm(x, m - 2, m); } void solve() { int n; cin >> n; int a = 0, b = 0, c = 0; int ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s.front() == 'B' && s.back() == 'A') c++; else if (s.front() == 'B') b++; else if (s.back() == 'A') a++; for (int j = 0; j + 1 < sz(s); j++) { if (s[j] == 'A' && s[j + 1] == 'B') ans++; } } if (a == 0) { c--; a++; } cout << ans + min(a, b) + c << endl; } int main() { cin.sync_with_stdio(0); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define sz(c) (static_cast<int>(c.size())) #define endl "\n" #ifdef DEBUG #define dump(v) cerr << "[" #v << ":" << (v) << "]" << endl; #else #define dump(v) #endif typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; const ll MOD = (1e9 + 7); const ll INF = (1e9 + 123456789); const ll INFL = (INF * INF); inline ll addm(ll a, ll b, ll m = MOD) { return ((a + b) % m); } inline ll subm(ll a, ll b, ll m = MOD) { return (((a - b) % m + m) % m); } inline ll mulm(ll a, ll b, ll m = MOD) { return ((a * b) % m); } ll powm(ll a, ll b, ll m = MOD) { ll ret = (!b) ? 1 : powm(a, b / 2, m); return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m); } ll inv(ll x, ll m = MOD) { return powm(x, m - 2, m); } void solve() { int n; cin >> n; int a = 0, b = 0, c = 0; int ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s.front() == 'B' && s.back() == 'A') c++; else if (s.front() == 'B') b++; else if (s.back() == 'A') a++; for (int j = 0; j + 1 < sz(s); j++) { if (s[j] == 'A' && s[j + 1] == 'B') ans++; } } if (a == 0 && c > 0) { c--; a++; } cout << ans + min(a, b) + c << endl; } int main() { cin.sync_with_stdio(0); cin.tie(NULL); solve(); return 0; }
[ "control_flow.branch.if.condition.change" ]
868,289
868,290
u346692517
cpp
p03053
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define fi first #define se second using namespace std; using cd = complex<double>; typedef pair<int, int> pii; const int N = 3e3 + 5; const long long INF = 1e18; const int mod = 998244353; // 786433;//998244353; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, m; queue<pair<int, int>> BFS; int Dist[1005][1005]; char a[1005][1005]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { Dist[i][j] = 1000000; cin >> a[i][j]; if (a[i][j] == '#') { Dist[i][j] = 0; BFS.push(mp(i, j)); } } } while (BFS.empty() == false) { int x = BFS.front().fi, y = BFS.front().se; BFS.pop(); for (int i = 0; i < 4; i++) { if (Dist[x + dx[i]][y + dy[i]] > Dist[x][y] + 1) { Dist[x + dx[i]][y + dy[i]] = Dist[x][y] + 1; BFS.push(mp(x + dx[i], y + dy[i])); } } } int t = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { t = max(t, Dist[i][j]); } } cout << t; }
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define fi first #define se second using namespace std; using cd = complex<double>; typedef pair<int, int> pii; const int N = 3e3 + 5; const long long INF = 1e18; const int mod = 998244353; // 786433;//998244353; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, m; queue<pair<int, int>> BFS; int Dist[1005][1005]; char a[1005][1005]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { Dist[i][j] = 1000000; cin >> a[i][j]; if (a[i][j] == '#') { Dist[i][j] = 0; BFS.push(mp(i, j)); } } } while (BFS.empty() == false) { int x = BFS.front().fi, y = BFS.front().se; BFS.pop(); for (int i = 0; i < 4; i++) { if (Dist[x + dx[i]][y + dy[i]] > Dist[x][y] + 1) { Dist[x + dx[i]][y + dy[i]] = Dist[x][y] + 1; BFS.push(mp(x + dx[i], y + dy[i])); } } } int t = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { t = max(t, Dist[i][j]); } } cout << t; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
868,309
868,310
u960469574
cpp
p03053
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define fi first #define se second using namespace std; using cd = complex<double>; typedef pair<int, int> pii; const int N = 3e3 + 5; const long long INF = 1e18; const int mod = 998244353; // 786433;//998244353; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, m; queue<pair<int, int>> BFS; int Dist[1005][1005]; char a[1005][1005]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { Dist[i][j] = 5 * n; cin >> a[i][j]; if (a[i][j] == '#') { Dist[i][j] = 0; BFS.push(mp(i, j)); } } } while (BFS.empty() == false) { int x = BFS.front().fi, y = BFS.front().se; BFS.pop(); for (int i = 0; i < 4; i++) { if (Dist[x + dx[i]][y + dy[i]] > Dist[x][y] + 1) { Dist[x + dx[i]][y + dy[i]] = Dist[x][y] + 1; BFS.push(mp(x + dx[i], y + dy[i])); } } } int t = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { t = max(t, Dist[i][j]); } } cout << t; }
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define fi first #define se second using namespace std; using cd = complex<double>; typedef pair<int, int> pii; const int N = 3e3 + 5; const long long INF = 1e18; const int mod = 998244353; // 786433;//998244353; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, m; queue<pair<int, int>> BFS; int Dist[1005][1005]; char a[1005][1005]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { Dist[i][j] = 1000000; cin >> a[i][j]; if (a[i][j] == '#') { Dist[i][j] = 0; BFS.push(mp(i, j)); } } } while (BFS.empty() == false) { int x = BFS.front().fi, y = BFS.front().se; BFS.pop(); for (int i = 0; i < 4; i++) { if (Dist[x + dx[i]][y + dy[i]] > Dist[x][y] + 1) { Dist[x + dx[i]][y + dy[i]] = Dist[x][y] + 1; BFS.push(mp(x + dx[i], y + dy[i])); } } } int t = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { t = max(t, Dist[i][j]); } } cout << t; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "literal.number.change", "assignment.value.change", "expression.operation.binary.remove" ]
868,311
868,310
u960469574
cpp
p03053
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #define REP(_i, _a, _n) for (int _i = _a; _i <= _n; ++_i) #define PER(_i, _a, _n) for (int _i = _n; _i >= _a; --_i) #define hr putchar(10) #define pb push_back #define lc (o << 1) #define rc (lc | 1) #define mid ((l + r) >> 1) #define ls lc, l, mid #define rs rc, mid + 1, r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' #define DB(_a) \ ({ \ REP(_i, 1, n) cout << _a[_i] << ','; \ hr; \ }) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll qpow(ll a, ll n) { ll r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; } inline int rd() { int x = 0; char p = getchar(); while (p < '0' || p > '9') p = getchar(); while (p >= '0' && p <= '9') x = x * 10 + p - '0', p = getchar(); return x; } // head const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; const int N = 1e3 + 10; int n, m, d[N][N], vis[N][N]; char s[N][N]; queue<pii> q; int main() { scanf("%d%d", &n, &m); REP(i, 1, n) { scanf("%s", s[i] + 1); REP(j, 1, m) if (s[i][j] == '#') { vis[i][j] = 1; q.push(pii(i, j)); } } int ans = 0; while (q.size()) { pii u(q.front()); q.pop(); ans = d[u.x][u.y]; REP(k, 0, 3) { int x = u.x + dx[k], y = u.y + dy[k]; if (1 <= x && x <= n && 1 <= y && y <= n && !vis[x][y]) { q.push(pii(x, y)); vis[x][y] = 1; d[x][y] = d[u.x][u.y] + 1; } } } printf("%d\n", ans); }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #define REP(_i, _a, _n) for (int _i = _a; _i <= _n; ++_i) #define PER(_i, _a, _n) for (int _i = _n; _i >= _a; --_i) #define hr putchar(10) #define pb push_back #define lc (o << 1) #define rc (lc | 1) #define mid ((l + r) >> 1) #define ls lc, l, mid #define rs rc, mid + 1, r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' #define DB(_a) \ ({ \ REP(_i, 1, n) cout << _a[_i] << ','; \ hr; \ }) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll qpow(ll a, ll n) { ll r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; } inline int rd() { int x = 0; char p = getchar(); while (p < '0' || p > '9') p = getchar(); while (p >= '0' && p <= '9') x = x * 10 + p - '0', p = getchar(); return x; } // head const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; const int N = 1e3 + 10; int n, m, d[N][N], vis[N][N]; char s[N][N]; queue<pii> q; int main() { scanf("%d%d", &n, &m); REP(i, 1, n) { scanf("%s", s[i] + 1); REP(j, 1, m) if (s[i][j] == '#') { vis[i][j] = 1; q.push(pii(i, j)); } } int ans = 0; while (q.size()) { pii u(q.front()); q.pop(); ans = d[u.x][u.y]; REP(k, 0, 3) { int x = u.x + dx[k], y = u.y + dy[k]; if (1 <= x && x <= n && 1 <= y && y <= m && !vis[x][y]) { q.push(pii(x, y)); vis[x][y] = 1; d[x][y] = d[u.x][u.y] + 1; } } } printf("%d\n", ans); }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,323
868,324
u257336998
cpp
p03053
#include "bits/stdc++.h" using namespace std; void Main() { int H, W; cin >> H >> W; vector<vector<int>> A(H, vector<int>(W, 0)); int nbBlack = 0; queue<pair<int, int>> nextQue; for (int i = 0; i < H; ++i) { string s; cin >> s; for (int j = 0; j < W; ++j) { if (s[j] == '#') { A[i][j] = 1; ++nbBlack; nextQue.push(make_pair(i, j)); } else { A[i][j] = 0; } } } int ans = 0; while (nbBlack < H * W) { ++ans; queue<pair<int, int>> que = nextQue; queue<pair<int, int>>().swap(nextQue); while (!que.empty()) { int i = que.front().first; int j = que.front().second; que.pop(); if (i < H - 1 && A[i + 1][j] == 0) { nextQue.push(make_pair(i + 1, j)); A[i + 1][j] = 1; ++nbBlack; } if (i > 0 && A[i - 1][j] == 0) { nextQue.push(make_pair(i - 1, j)); A[i - 1][j] = 1; ++nbBlack; } if (j < W - 1 && A[i][j + 1] == 0) { nextQue.push(make_pair(i, j + 1)); A[i][j + 1] == 1; ++nbBlack; } if (j > 0 && A[i][j - 1] == 0) { nextQue.push(make_pair(i, j - 1)); A[i][j - 1] == 1; ++nbBlack; } } } cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include "bits/stdc++.h" using namespace std; void Main() { int H, W; cin >> H >> W; vector<vector<int>> A(H, vector<int>(W, 0)); int nbBlack = 0; queue<pair<int, int>> nextQue; for (int i = 0; i < H; ++i) { string s; cin >> s; for (int j = 0; j < W; ++j) { if (s[j] == '#') { A[i][j] = 1; ++nbBlack; nextQue.push(make_pair(i, j)); } else { A[i][j] = 0; } } } int ans = 0; while (nbBlack < H * W) { ++ans; queue<pair<int, int>> que = nextQue; queue<pair<int, int>>().swap(nextQue); while (!que.empty()) { int i = que.front().first; int j = que.front().second; que.pop(); if (i < H - 1 && A[i + 1][j] == 0) { nextQue.push(make_pair(i + 1, j)); A[i + 1][j] = 1; ++nbBlack; } if (i > 0 && A[i - 1][j] == 0) { nextQue.push(make_pair(i - 1, j)); A[i - 1][j] = 1; ++nbBlack; } if (j < W - 1 && A[i][j + 1] == 0) { nextQue.push(make_pair(i, j + 1)); A[i][j + 1] = 1; ++nbBlack; } if (j > 0 && A[i][j - 1] == 0) { nextQue.push(make_pair(i, j - 1)); A[i][j - 1] = 1; ++nbBlack; } } } cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
[ "expression.operation.compare.replace.remove", "assignment.replace.add", "misc.typo" ]
868,325
868,326
u138886316
cpp
p03053
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; int main() { int H, W; cin >> H >> W; vector<vector<string>> mat(H); queue<vector<P>> q; vector<P> p; rep(i, W) { string t; cin >> t; rep(j, H) { string tt = {t[j]}; mat[i].pb(tt); if (tt == "#") { p.pb({i, j}); } } } q.push(p); int count = 0; while (!q.empty()) { vector<P> pp = q.front(); // cout << "q.size(): " << q.size() << endl; q.pop(); vector<P> tmp; for (P p : pp) { // cout << "x: " << p.first << " y: " << p.second << endl; if (p.first > 0 && mat[p.first - 1][p.second] == ".") { mat[p.first - 1][p.second] = "#"; tmp.pb({p.first - 1, p.second}); } if (p.first < W - 1 && mat[p.first + 1][p.second] == ".") { mat[p.first + 1][p.second] = "#"; tmp.pb({p.first + 1, p.second}); } if (p.second > 0 && mat[p.first][p.second - 1] == ".") { mat[p.first][p.second - 1] = "#"; tmp.pb({p.first, p.second - 1}); } if (p.second < H - 1 && mat[p.first][p.second + 1] == ".") { mat[p.first][p.second + 1] = "#"; tmp.pb({p.first, p.second + 1}); } } if (!tmp.empty()) { q.push(tmp); } // cout << "count++" << endl; count++; } cout << count - 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; int main() { int H, W; cin >> H >> W; vector<vector<string>> mat(H); queue<vector<P>> q; vector<P> p; // cout << "B" << endl; // cout << "mat: " << mat.size() << endl; rep(i, H) { string t; cin >> t; // cout << "?" << endl; rep(j, W) { string tt = {t[j]}; // cout << "tt: " << tt << endl; mat[i].pb(tt); if (tt == "#") { p.pb({i, j}); } } } // cout << "C" << endl; q.push(p); // cout << "D" << endl; int count = 0; while (!q.empty()) { vector<P> pp = q.front(); // cout << "q.size(): " << q.size() << endl; q.pop(); vector<P> tmp; for (P p : pp) { // cout << "x: " << p.first << " y: " << p.second << endl; // cout << "1" << endl; if (p.first > 0 && mat[p.first - 1][p.second] == ".") { mat[p.first - 1][p.second] = "#"; tmp.pb({p.first - 1, p.second}); } // cout << "2" << endl; // cout << "21" << endl; // cout << "p.first: " << p.first << endl; // cout << "W: " << W << endl; // cout << "mat.size(): " << mat.size() << endl; if (p.first < H - 1 && mat[p.first + 1][p.second] == ".") { // cout << "22" << endl; mat[p.first + 1][p.second] = "#"; tmp.pb({p.first + 1, p.second}); } // cout << "3" << endl; if (p.second > 0 && mat[p.first][p.second - 1] == ".") { mat[p.first][p.second - 1] = "#"; tmp.pb({p.first, p.second - 1}); } // cout << "4" << endl; if (p.second < W - 1 && mat[p.first][p.second + 1] == ".") { mat[p.first][p.second + 1] = "#"; tmp.pb({p.first, p.second + 1}); } } if (!tmp.empty()) { q.push(tmp); } // cout << "count++" << endl; count++; } cout << count - 1 << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,329
868,330
u297738015
cpp
p03053
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; int main() { int H, W; cin >> H >> W; vector<vector<string>> mat(H); queue<vector<P>> q; vector<P> p; rep(i, H) { string t; cin >> t; rep(j, W) { string tt = {t[j]}; mat[i].pb(tt); if (tt == "#") { p.pb({i, j}); } } } q.push(p); int count = 0; while (!q.empty()) { vector<P> pp = q.front(); // cout << "q.size(): " << q.size() << endl; q.pop(); vector<P> tmp; for (P p : pp) { // cout << "x: " << p.first << " y: " << p.second << endl; if (p.first > 0 && mat[p.first - 1][p.second] == ".") { mat[p.first - 1][p.second] = "#"; tmp.pb({p.first - 1, p.second}); } if (p.first < W - 1 && mat[p.first + 1][p.second] == ".") { mat[p.first + 1][p.second] = "#"; tmp.pb({p.first + 1, p.second}); } if (p.second > 0 && mat[p.first][p.second - 1] == ".") { mat[p.first][p.second - 1] = "#"; tmp.pb({p.first, p.second - 1}); } if (p.second < H - 1 && mat[p.first][p.second + 1] == ".") { mat[p.first][p.second + 1] = "#"; tmp.pb({p.first, p.second + 1}); } } if (!tmp.empty()) { q.push(tmp); } // cout << "count++" << endl; count++; } cout << count - 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; int main() { int H, W; cin >> H >> W; vector<vector<string>> mat(H); queue<vector<P>> q; vector<P> p; // cout << "B" << endl; // cout << "mat: " << mat.size() << endl; rep(i, H) { string t; cin >> t; // cout << "?" << endl; rep(j, W) { string tt = {t[j]}; // cout << "tt: " << tt << endl; mat[i].pb(tt); if (tt == "#") { p.pb({i, j}); } } } // cout << "C" << endl; q.push(p); // cout << "D" << endl; int count = 0; while (!q.empty()) { vector<P> pp = q.front(); // cout << "q.size(): " << q.size() << endl; q.pop(); vector<P> tmp; for (P p : pp) { // cout << "x: " << p.first << " y: " << p.second << endl; // cout << "1" << endl; if (p.first > 0 && mat[p.first - 1][p.second] == ".") { mat[p.first - 1][p.second] = "#"; tmp.pb({p.first - 1, p.second}); } // cout << "2" << endl; // cout << "21" << endl; // cout << "p.first: " << p.first << endl; // cout << "W: " << W << endl; // cout << "mat.size(): " << mat.size() << endl; if (p.first < H - 1 && mat[p.first + 1][p.second] == ".") { // cout << "22" << endl; mat[p.first + 1][p.second] = "#"; tmp.pb({p.first + 1, p.second}); } // cout << "3" << endl; if (p.second > 0 && mat[p.first][p.second - 1] == ".") { mat[p.first][p.second - 1] = "#"; tmp.pb({p.first, p.second - 1}); } // cout << "4" << endl; if (p.second < W - 1 && mat[p.first][p.second + 1] == ".") { mat[p.first][p.second + 1] = "#"; tmp.pb({p.first, p.second + 1}); } } if (!tmp.empty()) { q.push(tmp); } // cout << "count++" << endl; count++; } cout << count - 1 << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,331
868,330
u297738015
cpp
p03053
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) // REP(i, 5) cout<<i; #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define MOD 1000000007 // 10^9+7 //#define MOD 1 ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } const int MAX = 2000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int 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; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void sosuu(ll n, vector<ll> &v) { vector<ll> num(n, 0); FOR(i, 1, sqrt(n)) { if (num[i] == 0) { FOR(j, 0, n / i) { num[i + (j * i)] = 1; } } } REP(i, n) { if (num[i] == 0) v.push_back(i + 1); } } ll GetDigit(ll num) { ll digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } int main(void) { ll h, w; cin >> h >> w; char M[h][w]; queue<pair<ll, ll>> q; ll V[h][w]; REP(i, h) { REP(j, w) { char x; cin >> x; M[i][j] = x; V[i][j] = -1; if (x == '#') { V[i][j]++; q.push(make_pair(i, j)); } } } ll d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; while (q.size() != 0) { pair<ll, ll> now = q.front(); q.pop(); ll sx = now.first; ll sy = now.second; //.cout<<sx<<","<<sy<<endl; REP(i, 4) { ll nx = sx + d[i][0]; ll ny = sy + d[i][1]; if (nx >= 0 && ny >= 0 && nx <= h && ny <= w && M[nx][ny] == '.' && V[nx][ny] == -1) { q.push(make_pair(nx, ny)); V[nx][ny] = V[sx][sy] + 1; M[nx][ny] = '#'; } } } ll ans = 0; REP(i, h) { REP(j, w) { // cout<<V[i][j]; ans = max(V[i][j], ans); } // cout<<endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) // REP(i, 5) cout<<i; #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define MOD 1000000007 // 10^9+7 //#define MOD 1 ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } const int MAX = 2000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int 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; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void sosuu(ll n, vector<ll> &v) { vector<ll> num(n, 0); FOR(i, 1, sqrt(n)) { if (num[i] == 0) { FOR(j, 0, n / i) { num[i + (j * i)] = 1; } } } REP(i, n) { if (num[i] == 0) v.push_back(i + 1); } } ll GetDigit(ll num) { ll digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } int main(void) { ll h, w; cin >> h >> w; char M[h][w]; queue<pair<ll, ll>> q; ll V[h][w]; REP(i, h) { REP(j, w) { char x; cin >> x; M[i][j] = x; V[i][j] = -1; if (x == '#') { V[i][j]++; q.push(make_pair(i, j)); } } } ll d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; while (q.size() != 0) { pair<ll, ll> now = q.front(); q.pop(); ll sx = now.first; ll sy = now.second; //.cout<<sx<<","<<sy<<endl; REP(i, 4) { ll nx = sx + d[i][0]; ll ny = sy + d[i][1]; if (nx >= 0 && ny >= 0 && nx < h && ny < w && M[nx][ny] == '.' && V[nx][ny] == -1) { q.push(make_pair(nx, ny)); V[nx][ny] = V[sx][sy] + 1; M[nx][ny] = '#'; } } } ll ans = 0; REP(i, h) { REP(j, w) { // cout<<V[i][j]; ans = max(V[i][j], ans); } // cout<<endl; } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
868,357
868,358
u939401127
cpp
p03053
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<int> px = {0, 1, 0, -1}; vector<int> py = {1, 0, -1, 0}; int main() { int h, w, numPoints = 0, ans = 0; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) cin >> a[i]; vector<vector<bool>> isBlack(h, vector<bool>(w, false)); queue<pair<int, int>> que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') { isBlack[i][j] = true; que.push({i, j}); numPoints++; } } } while (!que.empty()) { vector<pair<int, int>> points; int numNewPoints = 0; for (int i = 0; i < numPoints; i++) { points.push_back(que.front()); que.pop(); for (int j = 0; j < 4; j++) { int nx = points[i].first + px[j]; int ny = points[i].second + py[j]; if (nx < 0 || nx >= h || ny < 0 || ny >= j) continue; if (isBlack[nx][ny]) continue; isBlack[nx][ny] = true; que.push({nx, ny}); numNewPoints++; } } numPoints = numNewPoints; ans++; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<int> px = {0, 1, 0, -1}; vector<int> py = {1, 0, -1, 0}; int main() { int h, w, numPoints = 0, ans = 0; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) cin >> a[i]; vector<vector<bool>> isBlack(h, vector<bool>(w, false)); queue<pair<int, int>> que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') { isBlack[i][j] = true; que.push({i, j}); numPoints++; } } } while (!que.empty()) { vector<pair<int, int>> points; int numNewPoints = 0; for (int i = 0; i < numPoints; i++) { points.push_back(que.front()); que.pop(); for (int j = 0; j < 4; j++) { int nx = points[i].first + px[j]; int ny = points[i].second + py[j]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (isBlack[nx][ny]) continue; isBlack[nx][ny] = true; que.push({nx, ny}); numNewPoints++; } } numPoints = numNewPoints; ans++; } cout << ans - 1 << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,359
868,360
u197206619
cpp
p03053
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = (1e9) + 7; using P = pair<ll, ll>; int main() { int h, w; cin >> h >> w; char a; vector<vector<ll>> turn(h, vector<ll>(w, INF)); queue<P> now; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> a; if (a == '#') { turn[i][j] = 0; now.push({i, j}); } } } vector<int> dx = {1, -1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; while (!now.empty()) { P pos; pos = now.front(); now.pop(); ll ns = turn[pos.first][pos.second]; // cout <<ns<<endl; for (int i = 0; i < 4; ++i) { int x = pos.first + dx[i]; int y = pos.second + dy[i]; // if(pos.first==0&&pos.second==1){ // cout <<x<<" "<<y<<endl; // } if (x >= w || x < 0) continue; if (y >= h || y < 0) continue; // if(x==0&&y==0){ // cout <<turn[x][y]<<" "<<ns+1<<endl; // } if (turn[x][y] > ns + 1) { now.push({x, y}); } turn[x][y] = min(turn[x][y], ns + 1); } } ll ans = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { // cout <<turn[i][j]<<" "; ans = max(ans, turn[i][j]); } // cout <<endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = (1e9) + 7; using P = pair<ll, ll>; int main() { int h, w; cin >> h >> w; char a; vector<vector<ll>> turn(h, vector<ll>(w, INF)); queue<P> now; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> a; if (a == '#') { turn[i][j] = 0; now.push({i, j}); } } } vector<int> dx = {1, -1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; while (!now.empty()) { P pos; pos = now.front(); now.pop(); ll ns = turn[pos.first][pos.second]; // cout <<ns<<endl; for (int i = 0; i < 4; ++i) { int x = pos.first + dx[i]; int y = pos.second + dy[i]; // if(pos.first==0&&pos.second==1){ // cout <<x<<" "<<y<<endl; // } if (x >= h || x < 0) continue; if (y >= w || y < 0) continue; // if(x==0&&y==0){ // cout <<turn[x][y]<<" "<<ns+1<<endl; // } if (turn[x][y] > ns + 1) { now.push({x, y}); } turn[x][y] = min(turn[x][y], ns + 1); } } ll ans = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { // cout <<turn[i][j]<<" "; ans = max(ans, turn[i][j]); } // cout <<endl; } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,372
868,373
u525008368
cpp
p03053
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = (1e9) + 7; using P = pair<ll, ll>; int main() { int h, w; cin >> h >> w; char a; vector<vector<ll>> turn(h, vector<ll>(w, INF)); queue<P> now; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { cin >> a; if (a == '#') { turn[i][j] = 0; now.push({i, j}); } } } vector<int> dx = {1, -1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; while (!now.empty()) { P pos; pos = now.front(); now.pop(); ll ns = turn[pos.first][pos.second]; // cout <<ns<<endl; for (int i = 0; i < 4; ++i) { int x = pos.first + dx[i]; int y = pos.second + dy[i]; // if(pos.first==0&&pos.second==1){ // cout <<x<<" "<<y<<endl; // } if (x >= w || x < 0) continue; if (y >= h || y < 0) continue; // if(x==0&&y==0){ // cout <<turn[x][y]<<" "<<ns+1<<endl; // } if (turn[x][y] > ns + 1) { now.push({x, y}); } turn[x][y] = min(turn[x][y], ns + 1); } } ll ans = 0; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { // cout <<turn[i][j]<<" "; ans = max(ans, turn[i][j]); } // cout <<endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = (1e9) + 7; using P = pair<ll, ll>; int main() { int h, w; cin >> h >> w; char a; vector<vector<ll>> turn(h, vector<ll>(w, INF)); queue<P> now; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> a; if (a == '#') { turn[i][j] = 0; now.push({i, j}); } } } vector<int> dx = {1, -1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; while (!now.empty()) { P pos; pos = now.front(); now.pop(); ll ns = turn[pos.first][pos.second]; // cout <<ns<<endl; for (int i = 0; i < 4; ++i) { int x = pos.first + dx[i]; int y = pos.second + dy[i]; // if(pos.first==0&&pos.second==1){ // cout <<x<<" "<<y<<endl; // } if (x >= h || x < 0) continue; if (y >= w || y < 0) continue; // if(x==0&&y==0){ // cout <<turn[x][y]<<" "<<ns+1<<endl; // } if (turn[x][y] > ns + 1) { now.push({x, y}); } turn[x][y] = min(turn[x][y], ns + 1); } } ll ans = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { // cout <<turn[i][j]<<" "; ans = max(ans, turn[i][j]); } // cout <<endl; } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change" ]
868,374
868,373
u525008368
cpp
p03053
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int h, w; cin >> h >> w; int m[h][w]; queue<pair<int, int>> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char c; cin >> c; if (c == '#') { m[i][j] = 0; q.push(make_pair(i, j)); } else { m[i][j] = -1; } } } while (!q.empty()) { auto a = q.front(); q.pop(); int i = a.first; int j = a.second; if (i > 0 && m[i - 1][j] == -1) { m[i - 1][j] = m[i][j] + 1; q.push(make_pair(i - 1, j)); } if (i < h && m[i + 1][j] == -1) { m[i + 1][j] = m[i][j] + 1; q.push(make_pair(i + 1, j)); } if (j > 0 && m[i][j - 1] == -1) { m[i][j - 1] = m[i][j] + 1; q.push(make_pair(i, j - 1)); } if (j < w && m[i][j + 1] == -1) { m[i][j + 1] = m[i][j] + 1; q.push(make_pair(i, j + 1)); } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, m[i][j]); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int h, w; cin >> h >> w; int m[h][w]; queue<pair<int, int>> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char c; cin >> c; if (c == '#') { m[i][j] = 0; q.push(make_pair(i, j)); } else { m[i][j] = -1; } } } while (!q.empty()) { auto a = q.front(); q.pop(); int i = a.first; int j = a.second; if (i > 0 && m[i - 1][j] == -1) { m[i - 1][j] = m[i][j] + 1; q.push(make_pair(i - 1, j)); } if (i < h - 1 && m[i + 1][j] == -1) { m[i + 1][j] = m[i][j] + 1; q.push(make_pair(i + 1, j)); } if (j > 0 && m[i][j - 1] == -1) { m[i][j - 1] = m[i][j] + 1; q.push(make_pair(i, j - 1)); } if (j < w - 1 && m[i][j + 1] == -1) { m[i][j + 1] = m[i][j] + 1; q.push(make_pair(i, j + 1)); } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, m[i][j]); } } cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
868,389
868,390
u313766957
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; vector<string> A; int H, W; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int d[1000][1000]; int INF = 1e9 + 7; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> H >> W; for (int i = 0; i < H; i++) { string tmp; cin >> tmp; A.push_back(tmp); } queue<P> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { que.push(P(i, j)); d[i][j] = 0; } else { d[i][j] = INF; } } } while (!que.empty()) { P p = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = p.first + dx[i]; int ny = p.second + dy[i]; if (0 <= nx && nx < W && 0 <= ny && ny < H && d[nx][ny] > d[p.first][p.second] + 1) { d[nx][ny] = d[p.first][p.second] + 1; que.push(P(nx, ny)); } } } 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; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; vector<string> A; int H, W; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int d[1000][1000]; int INF = 1e9 + 7; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> H >> W; for (int i = 0; i < H; i++) { string tmp; cin >> tmp; A.push_back(tmp); } queue<P> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { que.push(P(i, j)); d[i][j] = 0; } else { d[i][j] = INF; } } } while (!que.empty()) { P p = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = p.first + dx[i]; int ny = p.second + dy[i]; if (0 <= nx && nx < H && 0 <= ny && ny < W && d[nx][ny] > d[p.first][p.second] + 1) { d[nx][ny] = d[p.first][p.second] + 1; que.push(P(nx, ny)); } } } 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.branch.if.condition.change" ]
868,401
868,402
u059904258
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; ++i) { cin >> a[i]; } int dis[1010][1010]; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { dis[i][j] = INF; } } queue<pii> que; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (a[i][j] == '#') { que.push(pii(i, j)); dis[i][j] = 0; } } } while (!que.empty()) { pii p = que.front(); que.pop(); for (int k = 0; k < 4; ++k) { int nx = p.first + dx[k]; int ny = p.second + dy[k]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (a[nx][ny] == '#' || dis[nx][ny] != INF) continue; que.push(pii(nx, ny)); dis[nx][ny] = dis[p.first][p.second] + 1; } } int res = 0; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { res = max(res, dis[i][j]); } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; ++i) { cin >> a[i]; } int dis[1010][1010]; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { dis[i][j] = INF; } } queue<pii> que; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (a[i][j] == '#') { que.push(pii(i, j)); dis[i][j] = 0; } } } while (!que.empty()) { pii p = que.front(); que.pop(); for (int k = 0; k < 4; ++k) { int nx = p.first + dx[k]; int ny = p.second + dy[k]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (a[nx][ny] == '#' || dis[nx][ny] != INF) continue; que.push(pii(nx, ny)); dis[nx][ny] = dis[p.first][p.second] + 1; } } int res = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { res = max(res, dis[i][j]); } } cout << res << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
868,405
868,406
u743124029
cpp
p03053
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; const int INF = 100000000; typedef pair<int, int> P; char maze[55][55]; int h, w; vector<P> start; int d[55][55]; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; void bfs() { queue<P> que; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) d[i][j] = INF; for (auto itr = start.begin(); itr != start.end(); ++itr) { que.push(*itr); d[itr->second][itr->first] = 0; } while (que.size()) { P p = que.front(); que.pop(); for (int i = 0; i < 4; ++i) { int nx = p.first + dx[i], ny = p.second + dy[i]; if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' && d[ny][nx] == INF) { que.push(P(nx, ny)); d[ny][nx] = d[p.second][p.first] + 1; } } } return; } int main() { cin >> h >> w; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> maze[i][j]; if (maze[i][j] == '#') start.push_back(P(j, i)); } } bfs(); int ans; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { ans = max(ans, d[i][j]); } } cout << ans << "\n"; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; const int INF = 100000000; typedef pair<int, int> P; char maze[1010][1010]; int h, w; vector<P> start; int d[1010][1010]; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; void bfs() { queue<P> que; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) d[i][j] = INF; for (auto itr = start.begin(); itr != start.end(); ++itr) { que.push(*itr); d[itr->second][itr->first] = 0; } while (que.size()) { P p = que.front(); que.pop(); for (int i = 0; i < 4; ++i) { int nx = p.first + dx[i], ny = p.second + dy[i]; if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' && d[ny][nx] == INF) { que.push(P(nx, ny)); d[ny][nx] = d[p.second][p.first] + 1; } } } return; } int main() { cin >> h >> w; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> maze[i][j]; if (maze[i][j] == '#') start.push_back(P(j, i)); } } bfs(); 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 << "\n"; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change" ]
868,409
868,408
u743124029
cpp
p03053
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> a(H); vector<vector<char>> A(H, vector<char>(W)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = a[i][j]; } } queue<long int> q; queue<long int> sub; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { q.push(W * i + j); } } } int ans = 0; while (q.size()) { while (q.size()) { long int i = q.front(); q.pop(); int h = i / W; int w = i % W; if (h != H - 1 && A.at(h + 1).at(w) == '.') { A.at(h + 1).at(w) = '#'; sub.push(i + H); } if (h != 0 && A.at(h - 1).at(w) == '.') { A.at(h - 1).at(w) = '#'; sub.push(i - H); } if (w != W - 1 && A.at(h).at(w + 1) == '.') { A.at(h).at(w + 1) = '#'; sub.push(i + 1); } if (w != 0 && A.at(h).at(w - 1) == '.') { A.at(h).at(w - 1) = '#'; sub.push(i - 1); } } if (sub.size()) { ans += 1; } while (sub.size()) { long int i = sub.front(); sub.pop(); q.push(i); } } cout << ans; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> a(H); vector<vector<char>> A(H, vector<char>(W)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = a[i][j]; } } queue<long int> q; queue<long int> sub; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { q.push(W * i + j); } } } int ans = 0; while (q.size()) { while (q.size()) { long int i = q.front(); q.pop(); int h = i / W; int w = i % W; if (h != H - 1 && A.at(h + 1).at(w) == '.') { A.at(h + 1).at(w) = '#'; sub.push(i + W); } if (h != 0 && A.at(h - 1).at(w) == '.') { A.at(h - 1).at(w) = '#'; sub.push(i - W); } if (w != W - 1 && A.at(h).at(w + 1) == '.') { A.at(h).at(w + 1) = '#'; sub.push(i + 1); } if (w != 0 && A.at(h).at(w - 1) == '.') { A.at(h).at(w - 1) = '#'; sub.push(i - 1); } } if (sub.size()) { ans += 1; } while (sub.size()) { long int i = sub.front(); sub.pop(); q.push(i); } } cout << ans; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
868,420
868,421
u488401358
cpp
p03053
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> a(H); vector<vector<char>> A(H, vector<char>(W)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = a[i][j]; } } queue<long int> q; queue<long int> sub; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { q.push(W * i + j); } } } int ans = 0; while (q.size()) { while (q.size()) { long int i = q.front(); q.pop(); int h = i / W; int w = i % W; if (h != H - 1 && A.at(h + 1).at(w) == '.') { A.at(h + 1).at(w) = '#'; sub.push(i + H); } if (h != 0 && A.at(h - 1).at(w) == '.') { A.at(h - 1).at(w) = '#'; sub.push(i - H); } if (w != W - 1 && A.at(h).at(w + 1) == '.') { A.at(h).at(w + 1) = '#'; sub.push(i + 1); } if (w != 0 && A.at(h).at(w - 1) == '.') { A.at(h).at(w - 1) = '#'; sub.push(i - 1); } } if (sub.size()) { ans += 1; } while (sub.size()) { int i = sub.front(); sub.pop(); q.push(i); } } cout << ans; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> a(H); vector<vector<char>> A(H, vector<char>(W)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = a[i][j]; } } queue<long int> q; queue<long int> sub; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { q.push(W * i + j); } } } int ans = 0; while (q.size()) { while (q.size()) { long int i = q.front(); q.pop(); int h = i / W; int w = i % W; if (h != H - 1 && A.at(h + 1).at(w) == '.') { A.at(h + 1).at(w) = '#'; sub.push(i + W); } if (h != 0 && A.at(h - 1).at(w) == '.') { A.at(h - 1).at(w) = '#'; sub.push(i - W); } if (w != W - 1 && A.at(h).at(w + 1) == '.') { A.at(h).at(w + 1) = '#'; sub.push(i + 1); } if (w != 0 && A.at(h).at(w - 1) == '.') { A.at(h).at(w - 1) = '#'; sub.push(i - 1); } } if (sub.size()) { ans += 1; } while (sub.size()) { long int i = sub.front(); sub.pop(); q.push(i); } } cout << ans; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change", "variable_declaration.type.widen.change" ]
868,422
868,421
u488401358
cpp
p03053
#include <bits/stdc++.h> #define lld long long #define nmax 1005 #define pii pair<int, int> #define pb push_back using namespace std; int dl[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; int ans, n, m; queue<pii> q, q2; bool st[nmax][nmax]; char a[nmax][nmax]; bool interior(int i, int j) { return i >= 1 && j >= 1 && i <= n && j <= m; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> a[i][j]; if (a[i][j] == '#') { st[i][j] = true; q.push(make_pair(i, j)); } } } while (!q.empty()) { ++ans; while (!q2.empty()) { q2.pop(); } while (!q.empty()) { auto act = q.front(); int i = act.first, j = act.second; q.pop(); for (int k = 0; k < 4; ++k) { if (!interior(i + dl[k], j + dc[k])) { continue; } if (st[i + dl[k]][j + dc[k]]) { continue; } if (a[i + dl[k]][j + dc[k]] == '#') { continue; } st[i + dl[k]][j + dc[k]] = true; q2.push(make_pair(i + dl[k], j + dc[k])); } } q = q2; } --ans; if (ans < 0) { ans = 0; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define lld long long #define nmax 1005 #define pii pair<int, int> #define pb push_back using namespace std; int dl[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; int ans, n, m; queue<pii> q, q2; bool st[nmax][nmax]; char a[nmax][nmax]; bool interior(int i, int j) { return i >= 1 && j >= 1 && i <= n && j <= m; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; if (a[i][j] == '#') { st[i][j] = true; q.push(make_pair(i, j)); } } } while (!q.empty()) { ++ans; while (!q2.empty()) { q2.pop(); } while (!q.empty()) { auto act = q.front(); int i = act.first, j = act.second; q.pop(); for (int k = 0; k < 4; ++k) { if (!interior(i + dl[k], j + dc[k])) { continue; } if (st[i + dl[k]][j + dc[k]]) { continue; } if (a[i + dl[k]][j + dc[k]] == '#') { continue; } st[i + dl[k]][j + dc[k]] = true; q2.push(make_pair(i + dl[k], j + dc[k])); } } q = q2; } --ans; if (ans < 0) { ans = 0; } cout << ans << '\n'; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
868,446
868,447
u353919145
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; #define INF 1LL << 30 #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() // O(HW) int H, W; char maze[1010][1010]; int d[1010][1010]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { cin >> H >> W; queue<pair<int, int>> que; rep(i, H) { rep(j, W) { d[i][j] = INF; } } rep(i, H) { rep(j, H) { cin >> maze[i][j]; if (maze[i][j] == '#') { que.push(make_pair(i, j)); // (0,0)スタート d[i][j] = 0; } } } while (!que.empty()) { pair<int, int> p = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = p.first + dx[i]; int ny = p.second + dy[i]; if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF) { que.push(make_pair(nx, ny)); d[nx][ny] = d[p.first][p.second] + 1; } } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, d[i][j]); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; #define INF 1LL << 30 #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() // O(HW) int H, W; char maze[1010][1010]; int d[1010][1010]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { cin >> H >> W; queue<pair<int, int>> que; rep(i, H) { rep(j, W) { d[i][j] = INF; } } rep(i, H) { rep(j, W) { cin >> maze[i][j]; if (maze[i][j] == '#') { que.push(make_pair(i, j)); // (0,0)スタート d[i][j] = 0; } } } while (!que.empty()) { pair<int, int> p = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = p.first + dx[i]; int ny = p.second + dy[i]; if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF) { que.push(make_pair(nx, ny)); d[nx][ny] = d[p.first][p.second] + 1; } } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, d[i][j]); } } cout << ans << endl; }
[]
868,448
868,449
u633967774
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 #define INF 1e9 int main() { int h, w; cin >> h >> w; bool black[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { black[i][j] = false; } } string s[h]; for (int i = 0; i < w; i++) { cin >> s[i]; } queue<pair<int, int>> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') { black[h][w] = true; q.push(make_pair(i, j)); } } } int cnt_q = q.size(), cnt = 0; int ans = 0; while (!q.empty()) { if (cnt == cnt_q) { ans++; cnt = 0; cnt_q = q.size(); } pair<int, int> p = q.front(); q.pop(); int i = p.first; int j = p.second; if (i - 1 >= 0 && !black[i - 1][j]) { black[i - 1][j] = true; q.push(make_pair(i - 1, j)); } if (j - 1 >= 0 && !black[i][j - 1]) { black[i][j - 1] = true; q.push(make_pair(i, j - 1)); } if (j + 1 < w && !black[i][j + 1]) { black[i][j + 1] = true; q.push(make_pair(i, j + 1)); } if (i + 1 < h && !black[i + 1][j]) { black[i + 1][j] = true; q.push(make_pair(i + 1, j)); } cnt++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 #define INF 1e9 int main() { int h, w; cin >> h >> w; bool black[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { black[i][j] = false; } } string s[h]; for (int i = 0; i < h; i++) { cin >> s[i]; } queue<pair<int, int>> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') { black[i][j] = true; q.push(make_pair(i, j)); } } } int cnt_q = q.size(), cnt = 0; int ans = 0; while (!q.empty()) { if (cnt == cnt_q) { ans++; cnt = 0; cnt_q = q.size(); } pair<int, int> p = q.front(); q.pop(); int i = p.first; int j = p.second; if (i - 1 >= 0 && !black[i - 1][j]) { black[i - 1][j] = true; q.push(make_pair(i - 1, j)); } if (j - 1 >= 0 && !black[i][j - 1]) { black[i][j - 1] = true; q.push(make_pair(i, j - 1)); } if (j + 1 < w && !black[i][j + 1]) { black[i][j + 1] = true; q.push(make_pair(i, j + 1)); } if (i + 1 < h && !black[i + 1][j]) { black[i + 1][j] = true; q.push(make_pair(i + 1, j)); } cnt++; } cout << ans << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "assignment.variable.change", "variable_access.subscript.index.change" ]
868,452
868,451
u633967774
cpp
p03053
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) cin >> a[i]; // 多点スタート // スタートから0距離で到達できる場合には距離配列に0を格納 vector<vector<int>> dist(h, vector<int>(w, -1)); queue<pair<int, int>> que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') { dist[i][j] = 0; que.push(pair<int, int>(i, j)); } } } while (!que.empty()) { auto cur = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = cur.first + dx[i]; int ny = cur.second + dy[i]; if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue; if (dist[nx][ny] == -1) { que.push(pair<int, int>(nx, ny)); dist[nx][ny] = dist[cur.first][cur.second] + 1; } } } int res = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { res = max(res, dist[i][j]); } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) cin >> a[i]; // 多点スタート // スタートから0距離で到達できる場合には距離配列に0を格納 vector<vector<int>> dist(h, vector<int>(w, -1)); queue<pair<int, int>> que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') { dist[i][j] = 0; que.push(pair<int, int>(i, j)); } } } while (!que.empty()) { auto cur = que.front(); que.pop(); for (int i = 0; i < 4; i++) { int nx = cur.first + dx[i]; int ny = cur.second + dy[i]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (dist[nx][ny] == -1) { que.push(pair<int, int>(nx, ny)); dist[nx][ny] = dist[cur.first][cur.second] + 1; } } } int res = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { res = max(res, dist[i][j]); } } cout << res << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,453
868,454
u786667376
cpp
p03053
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define invrepr(i, a, b) for (int i = b - 1; i >= a; i--) #define invrep(i, n) invrepr(i, 0, n) #define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr) #define P pair<int, ll> const ll MOD = 998244353; const int INF = 1e9; const double PI = acos(-1); int main() { ios_base::sync_with_stdio(false); int h, w; cin >> h >> w; vector<string> a(h); rep(i, h) cin >> a[i]; vector<vector<int>> b(h, vector<int>(w, -1)); queue<P> q; vector<int> di = {-1, 0, 1, 0}, dj = {0, -1, 0, 1}; rep(i, h) { rep(j, w) { if (a[i][j] == '#') { b[i][j] = 0; q.push({i, j}); } } } while (!q.empty()) { P pp = q.front(); int i = pp.first, j = pp.second; q.pop(); rep(k, 4) { int ni = i + di[k], nj = j + dj[k]; if (ni >= 0 && ni < h && nj >= 0 && nj < h) { if (b[ni][nj] < 0) { b[ni][nj] = b[i][j] + 1; q.push({ni, nj}); } } } } int ans = 0; rep(i, h) { rep(j, w) ans = max(ans, b[i][j]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define invrepr(i, a, b) for (int i = b - 1; i >= a; i--) #define invrep(i, n) invrepr(i, 0, n) #define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr) #define P pair<int, ll> const ll MOD = 998244353; const int INF = 1e9; const double PI = acos(-1); int main() { ios_base::sync_with_stdio(false); int h, w; cin >> h >> w; vector<string> a(h); rep(i, h) cin >> a[i]; vector<vector<int>> b(h, vector<int>(w, -1)); queue<P> q; vector<int> di = {-1, 0, 1, 0}, dj = {0, -1, 0, 1}; rep(i, h) { rep(j, w) { if (a[i][j] == '#') { b[i][j] = 0; q.push({i, j}); } } } while (!q.empty()) { P pp = q.front(); int i = pp.first, j = pp.second; q.pop(); rep(k, 4) { int ni = i + di[k], nj = j + dj[k]; if (ni >= 0 && ni < h && nj >= 0 && nj < w) { if (b[ni][nj] < 0) { b[ni][nj] = b[i][j] + 1; q.push({ni, nj}); } } } } int ans = 0; rep(i, h) { rep(j, w) ans = max(ans, b[i][j]); } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,459
868,460
u012298376
cpp
p03053
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; queue<vector<ll>> bfs; char a[1010][1010]; int h, w; void search(vector<ll> pos) { for (int i = 0; i < 4; i++) { int x = pos[0] + dx[i]; int y = pos[1] + dy[i]; if (x < 0 || x >= w || y < 0 || y >= h) { continue; } if (a[x][y] != '#') { a[x][y] = '#'; bfs.push({x, y, pos[2] + 1}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; if (a[i][j] == '#') { bfs.push({i, j, 0}); } } } ll ans; while (bfs.size()) { vector<ll> tmp = bfs.front(); bfs.pop(); search(tmp); ans = tmp[2]; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; queue<vector<ll>> bfs; char a[1010][1010]; int h, w; void search(vector<ll> pos) { for (int i = 0; i < 4; i++) { int x = pos[0] + dx[i]; int y = pos[1] + dy[i]; if (x < 0 || x >= h || y < 0 || y >= w) { continue; } if (a[x][y] != '#') { a[x][y] = '#'; bfs.push({x, y, pos[2] + 1}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; if (a[i][j] == '#') { bfs.push({i, j, 0}); } } } ll ans; while (bfs.size()) { vector<ll> tmp = bfs.front(); bfs.pop(); search(tmp); ans = tmp[2]; } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,461
868,462
u012298376
cpp
p03053
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; queue<vector<int>> bfs; char a[1010][1010]; int h, w; void search(vector<int> pos) { for (int i = 0; i < 4; i++) { int x = pos[0] + dx[i]; int y = pos[1] + dy[i]; if (x < 0 || x >= w || y < 0 || y >= h) { continue; } if (a[x][y] != '#') { a[x][y] = '#'; bfs.push({x, y, pos[2] + 1}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; if (a[i][j] == '#') { bfs.push({i, j, 0}); } } } int ans; while (bfs.size()) { vector<int> tmp = bfs.front(); bfs.pop(); search(tmp); ans = tmp[2]; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; queue<vector<ll>> bfs; char a[1010][1010]; int h, w; void search(vector<ll> pos) { for (int i = 0; i < 4; i++) { int x = pos[0] + dx[i]; int y = pos[1] + dy[i]; if (x < 0 || x >= h || y < 0 || y >= w) { continue; } if (a[x][y] != '#') { a[x][y] = '#'; bfs.push({x, y, pos[2] + 1}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; if (a[i][j] == '#') { bfs.push({i, j, 0}); } } } ll ans; while (bfs.size()) { vector<ll> tmp = bfs.front(); bfs.pop(); search(tmp); ans = tmp[2]; } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change", "variable_declaration.type.change" ]
868,463
868,462
u012298376
cpp
p03053
#pragma GCC optimize(2) #include <bits/stdc++.h> #define ll long long #define maxn 1005 #define inf 1e9 #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; inline int read() { int x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c <= '9' && c >= '0') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return w == 1 ? x : -x; } char s[maxn][maxn]; const int kx[4] = {0, 0, 1, -1}; const int ky[4] = {1, -1, 0, 0}; queue<int> qx, qy; int d[maxn][maxn], n, m; int main() { n = read(); m = read(); rep(i, 1, n) scanf("%s", s[i] + 1); rep(i, 1, n) rep(j, 1, m) d[i][j] = inf; rep(i, 1, n) rep(j, 1, m) if (s[i][j] == '#') qx.push(i), qy.push(j), d[i][j] = 0; while (!qx.empty()) { int x = qx.front(), y = qy.front(); qx.pop(); qy.pop(); rep(k, 0, 3) { int tx = x + kx[k], ty = y + ky[k]; if (tx <= 0 || tx > n || ty <= 0 || ty > m) continue; if (d[tx][ty] != inf) continue; d[tx][ty] = d[x][y] + 1; qx.push(tx); qy.push(y); } } int ans = 0; rep(i, 1, n) rep(j, 1, m) ans = max(ans, d[i][j]); cout << ans << endl; return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> #define ll long long #define maxn 1005 #define inf 1e9 #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; inline int read() { int x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c <= '9' && c >= '0') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return w == 1 ? x : -x; } char s[maxn][maxn]; const int kx[4] = {0, 0, 1, -1}; const int ky[4] = {1, -1, 0, 0}; queue<int> qx, qy; int d[maxn][maxn], n, m; int main() { n = read(); m = read(); rep(i, 1, n) scanf("%s", s[i] + 1); rep(i, 1, n) rep(j, 1, m) d[i][j] = inf; rep(i, 1, n) rep(j, 1, m) if (s[i][j] == '#') qx.push(i), qy.push(j), d[i][j] = 0; while (!qx.empty()) { int x = qx.front(), y = qy.front(); qx.pop(); qy.pop(); rep(k, 0, 3) { int tx = x + kx[k], ty = y + ky[k]; if (tx <= 0 || tx > n || ty <= 0 || ty > m) continue; if (d[tx][ty] != inf) continue; d[tx][ty] = d[x][y] + 1; qx.push(tx); qy.push(ty); } } int ans = 0; rep(i, 1, n) rep(j, 1, m) ans = max(ans, d[i][j]); cout << ans << endl; return 0; }
[ "identifier.change", "call.arguments.change" ]
868,467
868,468
u766349042
cpp
p03053
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで #include <bits/stdc++.h> #define mod 1000000007 #define INF 1001001001 #define ll long long #define ln cout << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0; ll h, w; cin >> h >> w; string str[h]; ll chk[h][w]; deque<pair<ll, ll>> q; rep(i, h) cin >> str[i]; rep(i, h) { rep(j, w) { chk[i][j] = 0; if (str[i][j] == '#') { chk[i][j] = 1; q.push_back(make_pair(i, j)); } // cout<<chk[i][j]; } // ln; } q.push_back(make_pair(-100, -100)); while (q.size() != 1) { pair<ll, ll> p = q.front(); q.pop_front(); if (p.first == -100) { q.push_back(make_pair(-100, -100)); sum++; } else { rep(i, 4) { if (p.first + dy[i] < 0 || p.second + dx[i] < 0 || p.first + dy[i] > h - 1 || p.second + dx[i] > w - 1) continue; if (chk[p.first + dx[i]][p.second + dy[i]] == 0) { q.push_back(make_pair(p.first + dx[i], p.second + dy[i])); chk[p.first + dx[i]][p.second + dy[i]] = 1; } } } } cout << sum << endl; return 0; }
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで #include <bits/stdc++.h> #define mod 1000000007 #define INF 1001001001 #define ll long long #define ln cout << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0; ll h, w; cin >> h >> w; string str[h]; ll chk[h][w]; deque<pair<ll, ll>> q; rep(i, h) cin >> str[i]; rep(i, h) { rep(j, w) { chk[i][j] = 0; if (str[i][j] == '#') { chk[i][j] = 1; q.push_back(make_pair(i, j)); } } } // sum++; q.push_back(make_pair(-100, -100)); while (q.size() != 1) { pair<ll, ll> p = q.front(); q.pop_front(); if (p.first == -100) { q.push_back(make_pair(-100, -100)); sum++; } else { rep(i, 4) { if (p.first + dy[i] < 0 || p.second + dx[i] < 0 || p.first + dy[i] > h - 1 || p.second + dx[i] > w - 1) continue; // cout<<p.first+dy[i]<<" "<<p.second+dx[i]<<endl; if (chk[p.first + dy[i]][p.second + dx[i]] == 0) { q.push_back(make_pair(p.first + dy[i], p.second + dx[i])); chk[p.first + dy[i]][p.second + dx[i]] = 1; } } } // cout<<"loop"; } cout << sum << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "call.arguments.change", "expression.operation.binary.change", "assignment.variable.change" ]
868,473
868,474
u683769494
cpp
p03053
#include <bits/stdc++.h> #define Maxn 1007 using namespace std; int n, m; char a[Maxn][Maxn]; bool vis[Maxn][Maxn]; int ans = 0, dis[Maxn][Maxn]; int dx[4], dy[4]; pair<int, int> que[Maxn * Maxn * 2]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1); memset(vis, false, sizeof(vis)); int lx = 0, rx = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i][j] == '#') { vis[i][j] = true; dis[i][j] = 0; que[++rx] = make_pair(i, j); } dx[0] = 0, dy[0] = 1; dx[1] = 0, dy[1] = -1; dx[2] = 1, dy[2] = 0; dx[3] = -1, dy[3] = 0; while (lx < rx) { ++lx; int x = que[lx].first, y = que[lx].second; for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx >= 1 && xx <= n && yy >= 1 && yy <= n && (!vis[xx][yy])) { vis[xx][yy] = true; dis[xx][yy] = dis[x][y] + 1; ans = max(ans, dis[xx][yy]); que[++rx] = make_pair(xx, yy); } } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define Maxn 1007 using namespace std; int n, m; char a[Maxn][Maxn]; bool vis[Maxn][Maxn]; int ans = 0, dis[Maxn][Maxn]; int dx[4], dy[4]; pair<int, int> que[Maxn * Maxn * 2]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1); memset(vis, false, sizeof(vis)); int lx = 0, rx = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i][j] == '#') { vis[i][j] = true; dis[i][j] = 0; que[++rx] = make_pair(i, j); } dx[0] = 0, dy[0] = 1; dx[1] = 0, dy[1] = -1; dx[2] = 1, dy[2] = 0; dx[3] = -1, dy[3] = 0; while (lx < rx) { ++lx; int x = que[lx].first, y = que[lx].second; for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && (!vis[xx][yy])) { vis[xx][yy] = true; dis[xx][yy] = dis[x][y] + 1; ans = max(ans, dis[xx][yy]); que[++rx] = make_pair(xx, yy); } } } printf("%d\n", ans); return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,491
868,492
u018679195
cpp
p03053
#include <bits/stdc++.h> #define st first #define nd second using namespace std; void debug_out() { cerr << endl; } template <class T> ostream &prnt(ostream &out, T v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T> ostream &operator<<(ostream &out, vector<T> v) { return prnt(out, v); } template <class T> ostream &operator<<(ostream &out, set<T> v) { return prnt(out, v); } template <class T1, class T2> ostream &operator<<(ostream &out, map<T1, T2> v) { return prnt(out, v); } template <class T1, class T2> ostream &operator<<(ostream &out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__) #define dbg_v(x, n) \ do { \ cerr << #x "[]: "; \ for (int _ = 0; _ < n; ++_) \ cerr << x[_] << " "; \ cerr << '\n'; \ } while (0) #define dbg_ok cerr << "OK!\n" const int N = 2005; int n, mat[N][N], m, ans; string s[N]; queue<pair<int, int>> q; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; bool ok(int i, int j) { if (0 <= i && i < n) if (0 <= j & j < m) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 1; i < n; i++) for (int j = 0; j < m; j++) if (s[i][j] == '#') q.push({i, j}); while (!q.empty()) { auto p = q.front(); q.pop(); for (int i = 0; i < 4; i++) if (ok(p.st + dx[i], p.nd + dy[i]) && s[p.st + dx[i]][p.nd + dy[i]] == '.') { q.push({p.st + dx[i], p.nd + dy[i]}); s[p.st + dx[i]][p.nd + dy[i]] = '#'; mat[p.st + dx[i]][p.nd + dy[i]] = mat[p.st][p.nd] + 1; ans = max(ans, mat[p.st + dx[i]][p.nd + dy[i]]); } } cout << ans << '\n'; }
#include <bits/stdc++.h> #define st first #define nd second using namespace std; void debug_out() { cerr << endl; } template <class T> ostream &prnt(ostream &out, T v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T> ostream &operator<<(ostream &out, vector<T> v) { return prnt(out, v); } template <class T> ostream &operator<<(ostream &out, set<T> v) { return prnt(out, v); } template <class T1, class T2> ostream &operator<<(ostream &out, map<T1, T2> v) { return prnt(out, v); } template <class T1, class T2> ostream &operator<<(ostream &out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__) #define dbg_v(x, n) \ do { \ cerr << #x "[]: "; \ for (int _ = 0; _ < n; ++_) \ cerr << x[_] << " "; \ cerr << '\n'; \ } while (0) #define dbg_ok cerr << "OK!\n" const int N = 2005; int n, mat[N][N], m, ans; string s[N]; queue<pair<int, int>> q; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; bool ok(int i, int j) { if (0 <= i && i < n) if (0 <= j & j < m) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); 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++) { // dbg(s[i][j]); if (s[i][j] == '#') q.push({i, j}); } // dbg(q.size()); // dbg(s[0]); // dbg(s[1]); while (!q.empty()) { auto p = q.front(); // dbg(p); q.pop(); for (int i = 0; i < 4; i++) if (ok(p.st + dx[i], p.nd + dy[i]) && s[p.st + dx[i]][p.nd + dy[i]] == '.') { q.push({p.st + dx[i], p.nd + dy[i]}); s[p.st + dx[i]][p.nd + dy[i]] = '#'; mat[p.st + dx[i]][p.nd + dy[i]] = mat[p.st][p.nd] + 1; ans = max(ans, mat[p.st + dx[i]][p.nd + dy[i]]); } } cout << ans << '\n'; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
868,497
868,498
u089230684
cpp
p03053
// A - Darker and Darker #include <bits/stdc++.h> using namespace std; typedef long long ll; // const int INF = 2147483647; // const ll INF = 9223372036854775807; // const ll MOD = 1e9 + 7; char field[1000][1000]; bool visited[1000][1000]; struct Loc { int r; int c; int step; }; // 四方向への移動ベクトル const int dr[4] = {1, 0, -1, 0}; const int dc[4] = {0, 1, 0, -1}; int bfs(int H, int W) { queue<Loc> search_queue; for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { if (field[r][c] == '#') { search_queue.push(Loc{r, c, 0}); visited[r][c] = true; } } } int max_step; while (!search_queue.empty()) { // キューから探索対象の位置情報を取り出す Loc loc = search_queue.front(); search_queue.pop(); int r = loc.r; int c = loc.c; int step = loc.step; max_step = max(max_step, step); // cout << r << ' ' << c << " (" << s << ")" << endl; // **** debug **** // 四方向の探索を予約 for (int dir = 0; dir < 4; dir++) { int next_r = r + dr[dir]; int next_c = c + dc[dir]; if (next_r < 0 || next_r >= H || next_c < 0 || next_c >= W) continue; if (visited[next_r][next_c]) continue; search_queue.push(Loc{next_r, next_c, step + 1}); visited[next_r][next_c] = true; } } return max_step; } int main() { int H, W; cin >> H >> W; for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { cin >> field[r][c]; } } int ans = bfs(H, W); cout << ans << endl; return 0; }
// A - Darker and Darker #include <bits/stdc++.h> using namespace std; typedef long long ll; // const int INF = 2147483647; // const ll INF = 9223372036854775807; // const ll MOD = 1e9 + 7; char field[1000][1000]; bool visited[1000][1000]; struct Loc { int r; int c; int step; }; // 四方向への移動ベクトル const int dr[4] = {1, 0, -1, 0}; const int dc[4] = {0, 1, 0, -1}; int bfs(int H, int W) { queue<Loc> search_queue; for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { if (field[r][c] == '#') { search_queue.push(Loc{r, c, 0}); visited[r][c] = true; } } } int max_step = 0; while (!search_queue.empty()) { // キューから探索対象の位置情報を取り出す Loc loc = search_queue.front(); search_queue.pop(); int r = loc.r; int c = loc.c; int step = loc.step; max_step = max(max_step, step); // cout << r << ' ' << c << " (" << s << ")" << endl; // **** debug **** // 四方向の探索を予約 for (int dir = 0; dir < 4; dir++) { int next_r = r + dr[dir]; int next_c = c + dc[dir]; if (next_r < 0 || next_r >= H || next_c < 0 || next_c >= W) continue; if (visited[next_r][next_c]) continue; search_queue.push(Loc{next_r, next_c, step + 1}); visited[next_r][next_c] = true; } } return max_step; } int main() { int H, W; cin >> H >> W; for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { cin >> field[r][c]; } } int ans = bfs(H, W); cout << ans << endl; return 0; }
[ "variable_declaration.value.change" ]
868,501
868,502
u790272146
cpp
p03053
#include <iostream> #include <queue> using namespace std; int H, W; char A[1005][1005]; int dist[1005][1005]; bool visited[1005][1005]; int white_cnt = 0; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; class Node { public: int x, y; Node(int a, int b) : x(a), y(b) {} }; void input() { cin >> H >> W; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> A[i][j]; } } } void init() { for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { dist[i][j] = -1; } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { visited[i][j] = false; } } } void bfs() { init(); queue<Node> que; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (A[i][j] == '#') { Node temp(i, j); que.push(temp); visited[i][j] = true; dist[i][j] = 0; } } } while (!que.empty()) { Node cur = que.front(); que.pop(); int cur_x = cur.x; int cur_y = cur.y; for (int i = 0; i < 4; ++i) { int next_x = cur_x + dx[i]; int next_y = cur_y + dy[i]; bool b = 0 <= next_x && next_x < W && 0 <= next_y && next_y < H; if (A[next_y][next_x] == '#' || visited[next_y][next_x] || !b) continue; visited[next_y][next_x] = true; dist[next_y][next_x] = dist[cur_y][cur_x] + 1; Node next(next_x, next_y); que.push(next); } } } int max_search() { int ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { ans = ans < dist[i][j] ? dist[i][j] : ans; } } return ans; } void output() { cout << max_search() << endl; } int main() { input(); bfs(); output(); }
#include <iostream> #include <queue> using namespace std; int H, W; char A[1005][1005]; int dist[1005][1005]; bool visited[1005][1005]; int white_cnt = 0; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; class Node { public: int x, y; Node(int a, int b) : x(a), y(b) {} }; void input() { cin >> H >> W; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> A[i][j]; } } } void init() { for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { dist[i][j] = -1; } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { visited[i][j] = false; } } } void bfs() { init(); queue<Node> que; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (A[i][j] == '#') { Node temp(j, i); que.push(temp); visited[i][j] = true; dist[i][j] = 0; } } } while (!que.empty()) { Node cur = que.front(); que.pop(); int cur_x = cur.x; int cur_y = cur.y; for (int i = 0; i < 4; ++i) { int next_x = cur_x + dx[i]; int next_y = cur_y + dy[i]; bool b = 0 <= next_x && next_x < W && 0 <= next_y && next_y < H; if (A[next_y][next_x] == '#' || visited[next_y][next_x] || !b) continue; visited[next_y][next_x] = true; dist[next_y][next_x] = dist[cur_y][cur_x] + 1; Node next(next_x, next_y); que.push(next); } } } int max_search() { int ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { ans = ans < dist[i][j] ? dist[i][j] : ans; } } return ans; } void output() { cout << max_search() << endl; } int main() { input(); bfs(); output(); }
[]
868,514
868,515
u159943174
cpp
p03053
// includes #include "bits/stdc++.h" using namespace std; // macros #define ll long long #define MOD 1000000007 // 998244353 //100000000 // #define pii pair<ll, ll> #define piii pair<ll, pii> #define sz(x) ((ll)(x).size()) #define ft first #define sd second #define pb push_back #define rep(i, n) for (ll i = 0; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define itr(it, x) for (auto it = x.begin(); it != x.end(); it++) #define mem(a, b) memset(a, (ll)b, sizeof(a)) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define edge(v, x, y) \ v[x].pb(y); \ v[y].pb(x); #define popc __builtin_popcount #define ANS(s) \ { \ cout << s << "\n"; \ return; \ } // functions template <typename T> void unique(T &c) { c.erase(std::unique(c.begin(), c.end()), c.end()); } 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 (a > b) { a = b; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 != vec.size()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } // constants const ll N = 1e5 + 5, M = 1e6 + 5, A = 1e7 + 5, inf = 1e9; string alph("abcdefghijklmnopqrstuvwxyz"); const long long linf = 1LL << 60; const double er = 1e-10, pi = 3.141592653589793238463; const ll lx[4] = {0, 1, -1, 0}; const ll ly[4] = {1, 0, 0, -1}; const ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1}; const ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1}; // io struct fast_io { fast_io() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); } } fast_io_; void solve() { ll n, m; cin >> n >> m; char a[n][m]; ll vis[n][m]; mem(vis, 0); queue<piii> q; rep(i, n) { rep(j, m) { cin >> a[i][j]; if (a[i][j] == '#') { q.push({0, {i, j}}); } } } ll ans = 0; while (!q.empty()) { ll x = q.front().sd.ft, y = q.front().sd.sd; ll val = q.front().ft; q.pop(); if (vis[x][y]) continue; vis[x][y] = 1; ans = max(ans, val); rep(j, 4) { ll nx = x + lx[j]; ll ny = y + ly[j]; if (nx >= 0 && ny >= 0 && ny < n && nx < m) q.push({val + 1, {nx, ny}}); } } cout << ans; } int main(int argc, char const *argv[]) { ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
// includes #include "bits/stdc++.h" using namespace std; // macros #define ll long long #define MOD 1000000007 // 998244353 //100000000 // #define pii pair<ll, ll> #define piii pair<ll, pii> #define sz(x) ((ll)(x).size()) #define ft first #define sd second #define pb push_back #define rep(i, n) for (ll i = 0; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define itr(it, x) for (auto it = x.begin(); it != x.end(); it++) #define mem(a, b) memset(a, (ll)b, sizeof(a)) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define edge(v, x, y) \ v[x].pb(y); \ v[y].pb(x); #define popc __builtin_popcount #define ANS(s) \ { \ cout << s << "\n"; \ return; \ } // functions template <typename T> void unique(T &c) { c.erase(std::unique(c.begin(), c.end()), c.end()); } 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 (a > b) { a = b; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 != vec.size()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } // constants const ll N = 1e5 + 5, M = 1e6 + 5, A = 1e7 + 5, inf = 1e9; string alph("abcdefghijklmnopqrstuvwxyz"); const long long linf = 1LL << 60; const double er = 1e-10, pi = 3.141592653589793238463; const ll lx[4] = {0, 1, -1, 0}; const ll ly[4] = {1, 0, 0, -1}; const ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1}; const ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1}; // io struct fast_io { fast_io() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); } } fast_io_; void solve() { ll n, m; cin >> n >> m; char a[n][m]; ll vis[n][m]; mem(vis, 0); queue<piii> q; rep(i, n) { rep(j, m) { cin >> a[i][j]; if (a[i][j] == '#') { q.push({0, {i, j}}); } } } ll ans = 0; while (!q.empty()) { ll x = q.front().sd.ft, y = q.front().sd.sd; ll val = q.front().ft; q.pop(); if (vis[x][y]) continue; vis[x][y] = 1; ans = max(ans, val); rep(j, 4) { ll nx = x + lx[j]; ll ny = y + ly[j]; if (nx >= 0 && ny >= 0 && nx < n && ny < m) q.push({val + 1, {nx, ny}}); } } cout << ans; } int main(int argc, char const *argv[]) { ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,518
868,519
u448570453
cpp
p03053
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int H, W; cin >> H >> W; deque<pair<int, int>> path; vector<vector<int>> d(H, vector<int>(W)); vector<string> A(H); rep(i, 0, H) cin >> A[i]; rep(i, 0, H) { rep(i2, 0, W) { if (A[i][i2] == '#') path.push_back({i, i2}); } } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int ans = 0; while (path.size()) { auto it = path.front(); path.pop_front(); rep(i, 0, 4) { int tx = it.second + dx[i], ty = it.first + dy[i]; if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue; if (A[ty][tx] == '.' && d[ty][tx] == 0) { d[ty][tx] = d[it.second][it.first] + 1; ans = max(ans, d[ty][tx]); path.push_back({ty, tx}); } } } printf("%d\n", ans); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int H, W; cin >> H >> W; deque<pair<int, int>> path; vector<vector<int>> d(H, vector<int>(W)); vector<string> A(H); rep(i, 0, H) cin >> A[i]; rep(i, 0, H) { rep(i2, 0, W) { if (A[i][i2] == '#') path.push_back({i, i2}); } } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int ans = 0; while (path.size()) { auto it = path.front(); path.pop_front(); rep(i, 0, 4) { int tx = it.second + dx[i], ty = it.first + dy[i]; if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue; if (A[ty][tx] == '.' && d[ty][tx] == 0) { d[ty][tx] = d[it.first][it.second] + 1; ans = max(ans, d[ty][tx]); path.push_back({ty, tx}); } } /*rep(i, 0, H) { rep(i2, 0, W) { if (d[i][i2])printf("%d", d[i][i2]); else printf("%c", A[i][i2]); } puts(""); } puts("");*/ } printf("%d\n", ans); return 0; }
[ "assignment.value.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
868,520
868,521
u128572736
cpp
p03053
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int H, W; cin >> H >> W; deque<pair<int, int>> path; vector<vector<int>> d(H, vector<int>(W)); vector<string> A(H); rep(i, 0, H) cin >> A[i]; rep(i, 0, H) { rep(i2, 0, W) { if (A[i][i2] == '#') path.push_back({i, i2}); } } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int ans = 0; while (path.size()) { auto it = path.front(); path.pop_front(); rep(i, 0, 4) { int tx = it.second + dx[i], ty = it.first + dy[i]; if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue; if (A[ty][tx] == '.' && d[ty][tx] == 0) { d[ty][tx] = d[it.second][it.first] + 1; ans = max(ans, d[ty][tx]); path.push_back({tx, ty}); } } } printf("%d\n", ans); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int H, W; cin >> H >> W; deque<pair<int, int>> path; vector<vector<int>> d(H, vector<int>(W)); vector<string> A(H); rep(i, 0, H) cin >> A[i]; rep(i, 0, H) { rep(i2, 0, W) { if (A[i][i2] == '#') path.push_back({i, i2}); } } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int ans = 0; while (path.size()) { auto it = path.front(); path.pop_front(); rep(i, 0, 4) { int tx = it.second + dx[i], ty = it.first + dy[i]; if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue; if (A[ty][tx] == '.' && d[ty][tx] == 0) { d[ty][tx] = d[it.first][it.second] + 1; ans = max(ans, d[ty][tx]); path.push_back({ty, tx}); } } /*rep(i, 0, H) { rep(i2, 0, W) { if (d[i][i2])printf("%d", d[i][i2]); else printf("%c", A[i][i2]); } puts(""); } puts("");*/ } printf("%d\n", ans); return 0; }
[ "assignment.value.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
868,522
868,521
u128572736
cpp
p03053
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define int long long #define ll long long #define ld long double 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; } using P = pair<long long, long long>; #define rep(i, n) for (long long i = 0; i < (long long)n; i++) #define FOR(i, a, b) for (long long i = a; i < b; i++) #define all(x) (x).begin(), (x).end() #define SZ(x) ((long long)(x).size()) #define COUT(x) cout << x << endl #define PB push_back #define MP make_pair #define F first #define S second #define vint vector<int> #define vvint vector<vector<int>> #define vstr vector<string> #define vp vector<pair<int, int>> #define vb vector<bool> #define vvb vector<vector<bool>> #define SUM(x) accumulate(x.begin(), x.end(), 0) #define MAX(x) *max_element(x.begin(), x.end()) #define MIN(x) *min_element(x.begin(), x.end()) #define couty cout << "Yes" << endl #define coutn cout << "No" << endl #define coutY cout << "YES" << endl #define coutN cout << "NO" << endl #define yn(x) cout << (x ? "Yes" : "No") << endl #define YN(x) cout << (x ? "YES" : "NO") << endl long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } const long long dx[4] = {1, 0, -1, 0}; const long long dy[4] = {0, 1, 0, -1}; const long long INF = 1e12; const long long MOD = 1e9 + 7; signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int h, w; cin >> h >> w; vector<vector<char>> s(h + 2, vector<char>(w + 2, '#')); rep(i, h) { rep(j, w) { cin >> s[i + 1][j + 1]; } } queue<P> que; for (int i = 1; i < h + 1; i++) for (int j = 1; j < w + 1; j++) if (s[i][j] == '#') que.push(MP(i, j)); // rep(i,h+2){ // rep(j,w+2){ // cout<<s[i][j]; // } // cout<<endl; // } int res = -1; bool update = true; while (update) { res++; update = false; int num = que.size(); rep(i, num) { P p = que.front(); que.pop(); rep(j, 4) { if (s[p.S + dy[j]][p.F + dx[j]] == '.') { update = true; s[p.S + dy[j]][p.F + dx[j]] = '#'; que.push(MP(p.S + dy[j], p.F + dx[j])); } } } // rep(i,h+2){ // rep(j,w+2){ // cout<<s[i][j]; // } // cout<<endl; // } // cout<<endl; } cout << res << endl; }
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define int long long #define ll long long #define ld long double 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; } using P = pair<long long, long long>; #define rep(i, n) for (long long i = 0; i < (long long)n; i++) #define FOR(i, a, b) for (long long i = a; i < b; i++) #define all(x) (x).begin(), (x).end() #define SZ(x) ((long long)(x).size()) #define COUT(x) cout << x << endl #define PB push_back #define MP make_pair #define F first #define S second #define vint vector<int> #define vvint vector<vector<int>> #define vstr vector<string> #define vp vector<pair<int, int>> #define vb vector<bool> #define vvb vector<vector<bool>> #define SUM(x) accumulate(x.begin(), x.end(), 0) #define MAX(x) *max_element(x.begin(), x.end()) #define MIN(x) *min_element(x.begin(), x.end()) #define couty cout << "Yes" << endl #define coutn cout << "No" << endl #define coutY cout << "YES" << endl #define coutN cout << "NO" << endl #define yn(x) cout << (x ? "Yes" : "No") << endl #define YN(x) cout << (x ? "YES" : "NO") << endl long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } const long long dx[4] = {1, 0, -1, 0}; const long long dy[4] = {0, 1, 0, -1}; const long long INF = 1e12; const long long MOD = 1e9 + 7; signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int h, w; cin >> h >> w; vector<vector<char>> s(h + 2, vector<char>(w + 2, '#')); rep(i, h) { rep(j, w) { cin >> s[i + 1][j + 1]; } } queue<P> que; for (int i = 1; i < h + 1; i++) for (int j = 1; j < w + 1; j++) if (s[i][j] == '#') que.push(MP(i, j)); // rep(i,h+2){ // rep(j,w+2){ // cout<<s[i][j]; // } // cout<<endl; // } int res = -1; bool update = true; while (update) { res++; update = false; int num = que.size(); rep(i, num) { P p = que.front(); que.pop(); rep(j, 4) { if (s[p.F + dy[j]][p.S + dx[j]] == '.') { update = true; s[p.F + dy[j]][p.S + dx[j]] = '#'; que.push(MP(p.F + dy[j], p.S + dx[j])); } } } // rep(i,h+2){ // rep(j,w+2){ // cout<<s[i][j]; // } // cout<<endl; // } // cout<<endl; } cout << res << endl; }
[ "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "assignment.variable.change", "expression.operation.binary.change", "call.arguments.change" ]
868,531
868,532
u876953939
cpp
p03053
#include <bits/stdc++.h> 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; } using ll = long long; using P = pair<int, int>; using graph = vector<vector<char>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1 << 30; const ll mod = 1000000007LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int H, W; cin >> H >> W; graph g(H, vector<char>(W)); queue<P> bfs; vector<vector<int>> d(H, vector<int>(W, -1)); rep(i, H) { rep(j, W) { cin >> g[i][j]; if (g[i][j] == '#') { bfs.push(make_pair(i, j)); d[i][j] = 0; } } } while (!bfs.empty()) { P p = bfs.front(); bfs.pop(); int x = p.first; int y = p.second; rep(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || nx >= H || ny < 0 || ny >= H) continue; if (d[nx][ny] != -1) continue; d[nx][ny] = d[x][y] + 1; bfs.push(make_pair(nx, ny)); } } int ans = 0; rep(i, H) { rep(j, W) chmax(ans, d[i][j]); } cout << ans << endl; }
#include <bits/stdc++.h> 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; } using ll = long long; using P = pair<int, int>; using graph = vector<vector<char>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1 << 30; const ll mod = 1000000007LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int H, W; cin >> H >> W; graph g(H, vector<char>(W)); queue<P> bfs; vector<vector<int>> d(H, vector<int>(W, -1)); rep(i, H) { rep(j, W) { cin >> g[i][j]; if (g[i][j] == '#') { bfs.push(make_pair(i, j)); d[i][j] = 0; } } } while (!bfs.empty()) { P p = bfs.front(); bfs.pop(); int x = p.first; int y = p.second; rep(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue; if (d[nx][ny] != -1) continue; d[nx][ny] = d[x][y] + 1; bfs.push(make_pair(nx, ny)); } } int ans = 0; rep(i, H) { rep(j, W) chmax(ans, d[i][j]); } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,539
868,540
u787139585
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<double> vd; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<vector<int>> vvint; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; //小さい順に取り出し typedef priority_queue<int, vector<int>, less<int>> bpqint; //大きい順に取り出し typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; //大きい順に取り出し #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++) #define FI first #define SE second #define MP make_pair #define MT make_tuple #define PB push_back #define PF push_front #define TS to_string #define BS binary_search #define LB lower_bound #define UB upper_bound #define NP next_permutation #define ALL(v) (v).begin(), (v).end() #define SZ(x) (ll) x.size() #define SP(x) setprecision((ll)x) int INF = 1e9; int NIL = -1; ll MOD = 1000000007; ll LINF = 1e18; double EPS = 1e-9; double PI = M_PI; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } //最小公倍数 void yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } //----------------------------------------- const ll MAX_V = 1e6 + 1; struct edge { ll to; ll cost; // iからの行き先とそのコストの情報 }; ll n; vector<edge> G[MAX_V]; // G[i]...iからの行き先(to)とコスト(cost)の情報を持つ ll d[MAX_V]; // d[i]...sからiへ行くのにかかるコストの最小 vector<ll> par; // par[i]...iの一個前 void dijkstra(int s) { priority_queue<pii, vector<pii>, greater<pii>> que; // pair<sからiへ行くのの暫定最小コスト、i>の優先度付きキュー REP(i, n) { d[i] = INF; par.PB(i); //はじめコストはINFとして初期化 } d[s] = 0; que.push(MP(0, s)); //自身へのコストは0としてqueへ入れる while (!que.empty()) { pii p = que.top(); que.pop(); int v = p.SE; // queが空になるまで取り出す if (d[v] < p.FI) { //すでにそれ以下があれば見る必要はない continue; } REP(i, SZ(G[v])) { // vを経由した行き先について edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { // vを経由した方がコストが小さいなら更新し、queに入れる d[e.to] = d[v] + e.cost; par[e.to] = v; que.push(MP(d[e.to], e.to)); } } } } //頂点tへの最短路 vector<int> get_path(int t) { vector<int> path; int i = t; while (i != par[i]) { path.PB(i); i = par[i]; } reverse(ALL(path)); return path; } //----------------------------------------- int main() { cin.tie(0); ios::sync_with_stdio(false); std::chrono::system_clock::time_point start, end; start = std::chrono::system_clock::now(); ll h, w; cin >> h >> w; n = h * w; vector<vector<char>> grid(h, vector<char>(w)); REP(i, h) { string s; cin >> s; REP(j, w) { grid[i][j] = s[j]; } } bool f = true; REP(i, h) { REP(j, w) { if (grid[i][j] == '.') { f = false; } } } if (f) { std::cout << 0 << endl; return 0; } REP(i, h) { REP(j, w) { if (grid[i][j] == '#') { edge e = {0, 0}; edge f = {i * w + j + 1, 0}; G[i * w + j + 1].PB(e); G[0].PB(f); continue; } int x, y; x = i; y = j; REP(k, 4) { int xx = x + dx[k]; int yy = y + dy[k]; if (0 <= xx && xx < h && 0 <= yy && yy < w) { edge e = {xx * w + yy + 1, 1}; edge f = {x * w + y + 1, 1}; G[x * w + y + 1].PB(e); G[xx * w + yy + 1].PB(f); } } } } dijkstra(0); sort(d, d + MAX_V); cout << d[MAX_V - 1] << endl; end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start) .count(); // std::cout << elapsed <<"ms"<< std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<double> vd; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<vector<int>> vvint; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; //小さい順に取り出し typedef priority_queue<int, vector<int>, less<int>> bpqint; //大きい順に取り出し typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; //大きい順に取り出し #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++) #define FI first #define SE second #define MP make_pair #define MT make_tuple #define PB push_back #define PF push_front #define TS to_string #define BS binary_search #define LB lower_bound #define UB upper_bound #define NP next_permutation #define ALL(v) (v).begin(), (v).end() #define SZ(x) (ll) x.size() #define SP(x) setprecision((ll)x) int INF = 1e9; int NIL = -1; ll MOD = 1000000007; ll LINF = 1e18; double EPS = 1e-9; double PI = M_PI; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } //最小公倍数 void yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } //----------------------------------------- const ll MAX_V = 1e6 + 1; struct edge { ll to; ll cost; // iからの行き先とそのコストの情報 }; ll n; vector<edge> G[MAX_V]; // G[i]...iからの行き先(to)とコスト(cost)の情報を持つ ll d[MAX_V]; // d[i]...sからiへ行くのにかかるコストの最小 vector<ll> par; // par[i]...iの一個前 void dijkstra(int s) { priority_queue<pii, vector<pii>, greater<pii>> que; // pair<sからiへ行くのの暫定最小コスト、i>の優先度付きキュー REP(i, n) { d[i] = INF; par.PB(i); //はじめコストはINFとして初期化 } d[s] = 0; que.push(MP(0, s)); //自身へのコストは0としてqueへ入れる while (!que.empty()) { pii p = que.top(); que.pop(); int v = p.SE; // queが空になるまで取り出す if (d[v] < p.FI) { //すでにそれ以下があれば見る必要はない continue; } REP(i, SZ(G[v])) { // vを経由した行き先について edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { // vを経由した方がコストが小さいなら更新し、queに入れる d[e.to] = d[v] + e.cost; par[e.to] = v; que.push(MP(d[e.to], e.to)); } } } } //頂点tへの最短路 vector<int> get_path(int t) { vector<int> path; int i = t; while (i != par[i]) { path.PB(i); i = par[i]; } reverse(ALL(path)); return path; } //----------------------------------------- int main() { cin.tie(0); ios::sync_with_stdio(false); std::chrono::system_clock::time_point start, end; start = std::chrono::system_clock::now(); ll h, w; cin >> h >> w; n = h * w + 1; vector<vector<char>> grid(h, vector<char>(w)); REP(i, h) { string s; cin >> s; REP(j, w) { grid[i][j] = s[j]; } } bool f = true; REP(i, h) { REP(j, w) { if (grid[i][j] == '.') { f = false; } } } if (f) { cout << 0 << endl; return 0; } REP(i, h) { REP(j, w) { if (grid[i][j] == '#') { edge e = {0, 0}; edge f = {i * w + j + 1, 0}; G[i * w + j + 1].PB(e); G[0].PB(f); continue; } int x, y; x = i; y = j; REP(k, 4) { int xx = x + dx[k]; int yy = y + dy[k]; if (0 <= xx && xx < h && 0 <= yy && yy < w) { edge e = {xx * w + yy + 1, 1}; edge f = {x * w + y + 1, 1}; G[x * w + y + 1].PB(e); G[xx * w + yy + 1].PB(f); } } } } dijkstra(0); sort(d, d + MAX_V); cout << d[MAX_V - 1] << endl; end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start) .count(); // std::cout << elapsed <<"ms"<< std::endl; return 0; }
[ "assignment.change" ]
868,543
868,544
u852449189
cpp
p03053
#include <bits/stdc++.h> #define P pair<int, int> using namespace std; const int INF = 1e5; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int main() { int h, w, a[1009][1009]; string s[1009]; cin >> h >> w; memset(a, -1, sizeof(a)); for (int i = 0; i < h; i++) cin >> s[i]; queue<P> q; for (int i = 0; i < h; i++) { for (int j = 0; j < h; j++) { if (s[i][j] == '#') { a[i][j] = 0; q.push(P(i, j)); } } } int mx = 0; while (!q.empty()) { P p = q.front(); q.pop(); int ci = p.first; int cj = p.second; for (int i = 0; i < 4; i++) { int ni = ci + dy[i]; int nj = cj + dx[i]; if (!(0 <= ni && ni < h && 0 <= nj && nj < w)) continue; if (a[ni][nj] == -1) { a[ni][nj] = a[ci][cj] + 1; mx = max(mx, a[ni][nj]); q.push(P(ni, nj)); } } } cout << mx << endl; }
#include <bits/stdc++.h> #define P pair<int, int> using namespace std; const int INF = 1e5; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int main() { int h, w, a[1009][1009]; string s[1009]; cin >> h >> w; memset(a, -1, sizeof(a)); for (int i = 0; i < h; i++) cin >> s[i]; queue<P> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') { a[i][j] = 0; q.push(P(i, j)); } } } int mx = 0; while (!q.empty()) { P p = q.front(); q.pop(); int ci = p.first; int cj = p.second; for (int i = 0; i < 4; i++) { int ni = ci + dy[i]; int nj = cj + dx[i]; if (!(0 <= ni && ni < h && 0 <= nj && nj < w)) continue; if (a[ni][nj] == -1) { a[ni][nj] = a[ci][cj] + 1; mx = max(mx, a[ni][nj]); q.push(P(ni, nj)); } } } cout << mx << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
868,559
868,560
u112318601
cpp
p03053
#include <bits/stdc++.h> #include <cstdint> #include <vector> #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (l); i >= (int)(r); i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n - 1, 0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e9; const int mod = 1e9 + 7; vector<int> fac(MX); vector<int> ifac(MX); long long fpow(long long a, long long n) { long long ret = 1; if (n == 1) return a; if (n % 2 == 0) { ret = fpow(a * a % mod, n / 2) % mod; } else { ret = (a % mod) * fpow(a * a % mod, n / 2) % mod; } return ret % mod; } int comb(int a, int b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; int tmp = ifac[a - b] * ifac[b] % mod; return tmp * fac[a] % mod; } int P(int a, int b) { int res = comb(a, b); res *= fac[b]; return res % mod; } int ans, k; vector<int> to[100005]; void dfs(int v, int p = -1) { for (int u : to[v]) { if (u == p) continue; dfs(u, v); } int nk = (p == -1) ? k : k - 2; int c = (p == -1) ? to[v].size() + 1 : to[v].size() - 1; ans *= P(nk, c); ans %= mod; } char a[1002][1002]; signed main() { int h, w; cin >> h >> w; queue<pair<int, pair<int, int>>> q; FOR(i, 1, h + 1) { string str; cin >> str; FOR(j, 1, w + 1) { a[i][j] = str[j]; if (a[i][j] == '#') q.push(make_pair(0, make_pair(i, j))); } } int cnt = 0; while (q.size() > 0) { int i = q.front().second.first; int j = q.front().second.second; int depth = q.front().first; cnt = depth; q.pop(); if (a[i - 1][j] == '.') { a[i - 1][j] = '#'; q.push(make_pair(depth + 1, make_pair(i - 1, j))); } if (a[i][j - 1] == '.') { a[i][j - 1] = '#'; q.push(make_pair(depth + 1, make_pair(i, j - 1))); } if (a[i + 1][j] == '.') { a[i + 1][j] = '#'; q.push(make_pair(depth + 1, make_pair(i + 1, j))); } if (a[i][j + 1] == '.') { a[i][j + 1] = '#'; q.push(make_pair(depth + 1, make_pair(i, j + 1))); } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #include <cstdint> #include <vector> #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (l); i >= (int)(r); i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n - 1, 0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e9; const int mod = 1e9 + 7; vector<int> fac(MX); vector<int> ifac(MX); long long fpow(long long a, long long n) { long long ret = 1; if (n == 1) return a; if (n % 2 == 0) { ret = fpow(a * a % mod, n / 2) % mod; } else { ret = (a % mod) * fpow(a * a % mod, n / 2) % mod; } return ret % mod; } int comb(int a, int b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; int tmp = ifac[a - b] * ifac[b] % mod; return tmp * fac[a] % mod; } int P(int a, int b) { int res = comb(a, b); res *= fac[b]; return res % mod; } int ans, k; vector<int> to[100005]; void dfs(int v, int p = -1) { for (int u : to[v]) { if (u == p) continue; dfs(u, v); } int nk = (p == -1) ? k : k - 2; int c = (p == -1) ? to[v].size() + 1 : to[v].size() - 1; ans *= P(nk, c); ans %= mod; } char a[1002][1002]; signed main() { int h, w; cin >> h >> w; queue<pair<int, pair<int, int>>> q; FOR(i, 1, h + 1) { string str; cin >> str; FOR(j, 1, w + 1) { a[i][j] = str[j - 1]; // cout << a[i][j] << endl; if (a[i][j] == '#') q.push(make_pair(0, make_pair(i, j))); } } int cnt = 0; while (q.size() > 0) { int i = q.front().second.first; int j = q.front().second.second; int depth = q.front().first; // cout << depth <<" " << i <<" " << j << endl; cnt = depth; q.pop(); if (a[i - 1][j] == '.') { a[i - 1][j] = '#'; q.push(make_pair(depth + 1, make_pair(i - 1, j))); } if (a[i][j - 1] == '.') { a[i][j - 1] = '#'; q.push(make_pair(depth + 1, make_pair(i, j - 1))); } if (a[i + 1][j] == '.') { a[i + 1][j] = '#'; q.push(make_pair(depth + 1, make_pair(i + 1, j))); } if (a[i][j + 1] == '.') { a[i][j + 1] = '#'; q.push(make_pair(depth + 1, make_pair(i, j + 1))); } } cout << cnt << endl; return 0; }
[ "assignment.change" ]
868,561
868,562
u762160119
cpp
p03053
#include <bits/stdc++.h> using namespace std; struct xy { int x; int y; } node, top; const int dx[2] = {-1, 1}; int main() { int n, m; cin >> n >> m; vector<string> s(n); queue<xy> q; int cur = 0; 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] == '#') { node.x = i; node.y = j; q.push(node); cur++; } } int t = 0, tt = 0, curr = 0; bool ok = 0; while (!q.empty()) { top = q.front(); q.pop(); for (int i = 0; i <= 1; i++) { if (top.x + dx[i] >= 0 && top.x + dx[i] < n && s[top.x + dx[i]][top.y] == '.') { s[top.x + dx[i]][top.y] = '#'; node.x = top.x + dx[i]; node.y = top.y; q.push(node); curr++; ok = 1; } if (top.y + dx[i] >= 0 && top.y + dx[i] < m && s[top.x][top.y + dx[i]] == '.') { s[top.x][top.y + dx[i]] = '#'; node.x = top.x; node.y = top.y; q.push(node); curr++; ok = 1; } } t++; if (t == cur && ok) { tt++; cur += curr; curr = 0; ok = 0; } } // cout << t <<endl; cout << tt; return 0; }
#include <bits/stdc++.h> using namespace std; struct xy { int x; int y; } node, top; const int dx[2] = {-1, 1}; int main() { int n, m; cin >> n >> m; vector<string> s(n); queue<xy> q; int cur = 0; 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] == '#') { node.x = i; node.y = j; q.push(node); cur++; } } int t = 0, tt = 0, curr = 0; bool ok = 0; while (!q.empty()) { top = q.front(); q.pop(); for (int i = 0; i <= 1; i++) { if (top.x + dx[i] >= 0 && top.x + dx[i] < n && s[top.x + dx[i]][top.y] == '.') { s[top.x + dx[i]][top.y] = '#'; node.x = top.x + dx[i]; node.y = top.y; q.push(node); curr++; ok = 1; } if (top.y + dx[i] >= 0 && top.y + dx[i] < m && s[top.x][top.y + dx[i]] == '.') { s[top.x][top.y + dx[i]] = '#'; node.x = top.x; node.y = top.y + dx[i]; q.push(node); curr++; ok = 1; } } // cout << t << ' '<< cur << ' '<<curr <<' '<<ok <<endl; t++; if (t == cur && ok) { tt++; cur += curr; curr = 0; ok = 0; } } // cout << t <<endl; cout << tt; return 0; }
[ "assignment.change" ]
868,567
868,568
u633066470
cpp
p03053
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef long double louble; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t = buf; inline int fetch() { if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; } return *s++; } inline int ty() { int a = 0, b = 1, c = fetch(); while (!isdigit(c)) b ^= c == '-', c = fetch(); while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); return b ? a : -a; } inline int tc() { int c = fetch(); while (c <= 32 && c != EOF) c = fetch(); return c; } } // namespace ae86 using ae86::tc; using ae86::ty; const int _ = 1007; const int go[2][4] = {{1, 0, -1, 0}, {0, 1, 0, -1}}; int H, W, val[_][_], dis[_][_]; inline int bfs() { memset(dis, 63, sizeof(dis)); queue<pair<int, int>> q; for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) if (val[i][j]) dis[i][j] = 0, q.emplace(i, j); while (!q.empty()) { int x = q.front().first, y = q.front().second; q.pop(); for (int k = 0; k < 4; k++) { int xx = x + go[0][k], yy = y + go[1][k]; if (xx <= 0 || xx > W || yy <= 0 || yy > H) continue; if (dis[xx][yy] <= dis[x][y] + 1) continue; dis[xx][yy] = dis[x][y] + 1, q.emplace(xx, yy); } } int mx = 0; for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) mx = max(mx, dis[i][j]); return mx; } int main() { H = ty(), W = ty(); for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) val[i][j] = tc() == '#'; printf("%d\n", bfs()); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef long double louble; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t = buf; inline int fetch() { if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; } return *s++; } inline int ty() { int a = 0, b = 1, c = fetch(); while (!isdigit(c)) b ^= c == '-', c = fetch(); while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); return b ? a : -a; } inline int tc() { int c = fetch(); while (c <= 32 && c != EOF) c = fetch(); return c; } } // namespace ae86 using ae86::tc; using ae86::ty; const int _ = 1007; const int go[2][4] = {{1, 0, -1, 0}, {0, 1, 0, -1}}; int H, W, val[_][_], dis[_][_]; inline int bfs() { memset(dis, 63, sizeof(dis)); queue<pair<int, int>> q; for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) if (val[i][j]) dis[i][j] = 0, q.emplace(i, j); while (!q.empty()) { int x = q.front().first, y = q.front().second; q.pop(); for (int k = 0; k < 4; k++) { int xx = x + go[0][k], yy = y + go[1][k]; if (xx <= 0 || xx > H || yy <= 0 || yy > W) continue; if (dis[xx][yy] <= dis[x][y] + 1) continue; dis[xx][yy] = dis[x][y] + 1, q.emplace(xx, yy); } } int mx = 0; for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) mx = max(mx, dis[i][j]); return mx; } int main() { H = ty(), W = ty(); for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) val[i][j] = tc() == '#'; printf("%d\n", bfs()); return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,579
868,580
u326034736
cpp
p03053
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; ll abs1(ll a) { if (a >= 0) return a; else return -a; } ll gcd1(ll a, ll b) { if (a == 0 && b == 0) return 0; ll n; while (a % b != 0) { n = a % b; a = b; b = n; } return b; } ll solveLinear(ll n, ll m, ll c) { if (n == 0 && m == 0) return 0; ll a[100], b[100]; a[0] = n; b[0] = m; int i = 1; while (b[i - 1] != 0) { a[i] = b[i - 1]; b[i] = a[i - 1] % b[i - 1]; i++; } n = i; if (c % a[n - 1] != 0) { return 0; } ll x = c / a[n - 1], y = 0; for (i = 1; i < n; i++) { ll cnt = x; x = y; y = cnt - (a[n - i - 1] / b[n - i - 1]) * y; } return x; } ll modRev(ll a, ll p) { ll n = solveLinear(a, p, 1); n = n % p; if (n < 0) return n + p; return n; } int main() { int i, j, cnt = 0; int h, w; cin >> h >> w; char a[h][w]; for (i = 0; i < h; i++) for (j = 0; j < w; j++) cin >> a[i][j]; vector<pair<int, int>> v; int p[h][w]; for (i = 0; i < h; i++) for (j = 0; j < w; j++) p[i][j] = -1; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (a[i][j] == '#') { v.push_back(pair<int, int>(i, j)); p[i][j] = 0; } } } while (cnt != v.size()) { int x = v[cnt++].first, y = v[cnt].second; if (x > 0 && p[x - 1][y] == -1) { v.push_back(pair<int, int>(x - 1, y)); p[x - 1][y] = p[x][y] + 1; } if (x < h - 1 && p[x + 1][y] == -1) { v.push_back(pair<int, int>(x + 1, y)); p[x + 1][y] = p[x][y] + 1; } if (y > 0 && p[x][y - 1] == -1) { v.push_back(pair<int, int>(x, y - 1)); p[x][y - 1] = p[x][y] + 1; } if (y < w - 1 && p[x][y + 1] == -1) { v.push_back(pair<int, int>(x, y + 1)); p[x][y + 1] = p[x][y] + 1; } } int ma = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { ma = max(ma, p[i][j]); } } cout << ma << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; ll abs1(ll a) { if (a >= 0) return a; else return -a; } ll gcd1(ll a, ll b) { if (a == 0 && b == 0) return 0; ll n; while (a % b != 0) { n = a % b; a = b; b = n; } return b; } ll solveLinear(ll n, ll m, ll c) { if (n == 0 && m == 0) return 0; ll a[100], b[100]; a[0] = n; b[0] = m; int i = 1; while (b[i - 1] != 0) { a[i] = b[i - 1]; b[i] = a[i - 1] % b[i - 1]; i++; } n = i; if (c % a[n - 1] != 0) { return 0; } ll x = c / a[n - 1], y = 0; for (i = 1; i < n; i++) { ll cnt = x; x = y; y = cnt - (a[n - i - 1] / b[n - i - 1]) * y; } return x; } ll modRev(ll a, ll p) { ll n = solveLinear(a, p, 1); n = n % p; if (n < 0) return n + p; return n; } int main() { int i, j, cnt = 0; int h, w; cin >> h >> w; char a[h][w]; for (i = 0; i < h; i++) for (j = 0; j < w; j++) cin >> a[i][j]; vector<pair<int, int>> v; int p[h][w]; for (i = 0; i < h; i++) for (j = 0; j < w; j++) p[i][j] = -1; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (a[i][j] == '#') { v.push_back(pair<int, int>(i, j)); p[i][j] = 0; } } } while (cnt != v.size()) { int x = v[cnt].first, y = v[cnt++].second; if (x > 0 && p[x - 1][y] == -1) { v.push_back(pair<int, int>(x - 1, y)); p[x - 1][y] = p[x][y] + 1; } if (x < h - 1 && p[x + 1][y] == -1) { v.push_back(pair<int, int>(x + 1, y)); p[x + 1][y] = p[x][y] + 1; } if (y > 0 && p[x][y - 1] == -1) { v.push_back(pair<int, int>(x, y - 1)); p[x][y - 1] = p[x][y] + 1; } if (y < w - 1 && p[x][y + 1] == -1) { v.push_back(pair<int, int>(x, y + 1)); p[x][y + 1] = p[x][y] + 1; } } int ma = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { ma = max(ma, p[i][j]); } } cout << ma << endl; }
[]
868,582
868,583
u952130512
cpp
p03053
#include <bits/stdc++.h> using namespace std; #define rep(i, s, t) for (int i = s; i < t; i++) #define pii pair<int, int> #define MAXNUM 1111 char mat[MAXNUM][MAXNUM]; int isused[MAXNUM][MAXNUM]; pii q[MAXNUM * MAXNUM]; int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; int main() { int n, m; scanf("%d%d", &n, &m); rep(i, 1, n + 1) scanf("%s", mat[i] + 1); int top = 0, front = 0; rep(i, 1, n + 1) rep(j, 1, m + 1) if (mat[i][j] == '#') { isused[i][j] = 1; q[top++] = {i, j}; } while (top != front) { pii p = q[front++]; rep(j, 0, 4) { int newi = p.first + dir[j][0], newj = p.second + dir[j][1]; if (newi <= 0 || newi > n || newj <= 0 || newj >= m) continue; if (isused[newi][newj]) continue; isused[newi][newj] = isused[p.first][p.second] + 1; q[top++] = {newi, newj}; } } int res = 0; rep(i, 1, n + 1) rep(j, 1, m + 1) res = max(res, isused[i][j]); printf("%d\n", res - 1); }
#include <bits/stdc++.h> using namespace std; #define rep(i, s, t) for (int i = s; i < t; i++) #define pii pair<int, int> #define MAXNUM 1111 char mat[MAXNUM][MAXNUM]; int isused[MAXNUM][MAXNUM]; pii q[MAXNUM * MAXNUM]; int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; int main() { int n, m; scanf("%d%d", &n, &m); rep(i, 1, n + 1) scanf("%s", mat[i] + 1); int top = 0, front = 0; rep(i, 1, n + 1) rep(j, 1, m + 1) if (mat[i][j] == '#') { isused[i][j] = 1; q[top++] = {i, j}; } while (top != front) { pii p = q[front++]; rep(j, 0, 4) { int newi = p.first + dir[j][0], newj = p.second + dir[j][1]; if (newi <= 0 || newi > n || newj <= 0 || newj > m) continue; if (isused[newi][newj]) continue; isused[newi][newj] = isused[p.first][p.second] + 1; q[top++] = {newi, newj}; } } int res = 0; rep(i, 1, n + 1) rep(j, 1, m + 1) res = max(res, isused[i][j]); printf("%d\n", res - 1); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
868,584
868,585
u930038564
cpp
p03053
#include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < N; i++) #define rep2(i, N) for (int i = 1; i <= N; i++) using namespace std; long long INF = 1000000000000000000; long long mod = 1000000007; using namespace std; char maze[1010][1010]; bool checked[1010][1010] = {}; int main() { int h, w; cin >> h >> w; vector<queue<int>> q(2010); rep2(i, h) { rep2(k, w) { cin >> maze[i][k]; if (maze[i][k] == '#') { q[0].push(i); q[0].push(k); checked[i][k] = true; } } } long long p = 0; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; while (1) { bool finish = true; while (!q[p].empty()) { int x = q[p].front(); q[p].pop(); int y = q[p].front(); q[p].pop(); rep(i, 4) { int nowx = x + dx[i]; int nowy = y + dy[i]; if (!checked[nowy][nowx] && nowx <= w && nowx >= 1 && nowy <= h && nowy >= 1) { q[p + 1].push(nowx); q[p + 1].push(nowy); finish = false; checked[nowy][nowx] = true; } } } if (finish) break; p++; } cout << p << endl; return 0; } /* 3 3 ... .#. ... 2 6 6 ..#..# ...... #..#.. ...... .#.... ....#. 3 */
#include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < N; i++) #define rep2(i, N) for (int i = 1; i <= N; i++) using namespace std; long long INF = 1000000000000000000; long long mod = 1000000007; using namespace std; char maze[1010][1010]; bool checked[1010][1010] = {}; int main() { int h, w; cin >> h >> w; vector<queue<int>> q(2010); rep2(i, h) { rep2(k, w) { cin >> maze[i][k]; if (maze[i][k] == '#') { q[0].push(k); q[0].push(i); checked[i][k] = true; } } } long long p = 0; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; while (1) { bool finish = true; while (!q[p].empty()) { int x = q[p].front(); q[p].pop(); int y = q[p].front(); q[p].pop(); rep(i, 4) { int nowx = x + dx[i]; int nowy = y + dy[i]; if (!checked[nowy][nowx] && nowx <= w && nowx >= 1 && nowy <= h && nowy >= 1) { q[p + 1].push(nowx); q[p + 1].push(nowy); finish = false; checked[nowy][nowx] = true; } } } if (finish) break; p++; } cout << p << endl; return 0; } /* 3 3 ... .#. ... 2 6 6 ..#..# ...... #..#.. ...... .#.... ....#. 3 */
[ "call.remove", "call.add" ]
868,588
868,589
u120564432
cpp
p03053
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) int main() { int h, w; cin >> h >> w; vector<string> a(h); REP(i, h) { cin >> a[i]; } int ans = 0; queue<pint> q; vector<vector<int>> painted(h, vector<int>(w)); REP(i, h) REP(j, w) { if (a[i][j] == '#') { q.push(make_pair(i, j)); painted[i][j] = 1; } } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int count = 0; while (!q.empty()) { pint x = q.front(); q.pop(); REP(i, 4) { int ny = x.first + dx[i]; int nx = x.second + dy[i]; if (0 <= nx && nx < w && 0 <= ny && ny < h && painted[ny][nx] == 0) { q.push(make_pair(nx, ny)); painted[ny][nx] = painted[x.first][x.second] + 1; // ans = max(ans, painted[ny][nx]); } } count++; } REP(i, h) { REP(j, w) { // cout << painted[i][j] << " "; ans = max(ans, painted[i][j]); } // cout << "\n"; } cout << ans - 1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) int main() { int h, w; cin >> h >> w; vector<string> a(h); REP(i, h) { cin >> a[i]; } int ans = 0; queue<pint> q; vector<vector<int>> painted(h, vector<int>(w)); REP(i, h) REP(j, w) { if (a[i][j] == '#') { q.push(make_pair(i, j)); painted[i][j] = 1; } } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int count = 0; while (!q.empty()) { pint x = q.front(); q.pop(); REP(i, 4) { int ny = x.first + dy[i]; int nx = x.second + dx[i]; if (0 <= nx && nx < w && 0 <= ny && ny < h && painted[ny][nx] == 0) { q.push(make_pair(ny, nx)); painted[ny][nx] = painted[x.first][x.second] + 1; // ans = max(ans, painted[ny][nx]); } } count++; } REP(i, h) { REP(j, w) { // cout << painted[i][j] << " "; ans = max(ans, painted[i][j]); } // cout << "\n"; } cout << ans - 1 << "\n"; return 0; }
[ "identifier.change", "expression.operation.binary.change", "call.arguments.change", "call.arguments.add" ]
868,611
868,612
u517411077
cpp
p03053
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) const int INF = 1000000000; int main() { int H, W; cin >> H >> W; char info[H][W]; int ans[H][W]; queue<pair<int, int>> point; rep(i, H) rep(j, W) { cin >> info[i][j]; if (info[i][j] == '#') { point.push(make_pair(i, j)); ans[i][j] = 0; } else ans[i][j] = INF; } const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; while (point.size()) { int p = point.front().first, q = point.front().second; point.pop(); rep(i, 4) { if (0 <= p + dy[i] and p + dy[i] < W and 0 <= q + dx[i] and q + dx[i] <= H) { if (ans[p + dy[i]][q + dx[i]] == INF) { point.push(make_pair(p + dy[i], q + dx[i])); ans[p + dy[i]][q + dx[i]] = min(ans[p + dy[i]][q + dx[i]], ans[p][q] + 1); } } } } int count = 0; rep(i, H) rep(j, W) count = max(count, ans[i][j]); cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) const int INF = 1000000000; int main() { int H, W; cin >> H >> W; char info[H][W]; int ans[H][W]; queue<pair<int, int>> point; rep(i, H) rep(j, W) { cin >> info[i][j]; if (info[i][j] == '#') { point.push(make_pair(i, j)); ans[i][j] = 0; } else ans[i][j] = INF; } const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; while (point.size()) { int p = point.front().first, q = point.front().second; point.pop(); rep(i, 4) { if (0 <= p + dy[i] and p + dy[i] < H and 0 <= q + dx[i] and q + dx[i] < W) { if (ans[p + dy[i]][q + dx[i]] == INF) { point.push(make_pair(p + dy[i], q + dx[i])); ans[p + dy[i]][q + dx[i]] = min(ans[p + dy[i]][q + dx[i]], ans[p][q] + 1); } } } } int count = 0; rep(i, H) rep(j, W) count = max(count, ans[i][j]); cout << count << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
868,627
868,628
u936602931
cpp
p03053
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int H, W; cin >> H >> W; vector<string> s(H); for (int i = 0; i < H; i++) cin >> s[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i][j] == '.') { que.push(pair<int, int>(i, j)); dist[i][j] = 0; } } } int ans = 0; while (!que.empty()) { pair<int, int> v = que.front(); for (int i = 0; i < 4; i++) { int nx = v.first + dx[i]; int ny = v.second + dy[i]; if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1) continue; ans = (dist[nx][ny] = dist[v.first][v.second] + 1); que.push(pair<int, int>(nx, ny)); } que.pop(); } cout << ans << endl; return 0; }
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int H, W; cin >> H >> W; vector<string> s(H); for (int i = 0; i < H; i++) cin >> s[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i][j] == '#') { que.push(pair<int, int>(i, j)); dist[i][j] = 0; } } } int ans = 0; while (!que.empty()) { pair<int, int> v = que.front(); for (int i = 0; i < 4; i++) { int nx = v.first + dx[i]; int ny = v.second + dy[i]; if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1) continue; ans = (dist[nx][ny] = dist[v.first][v.second] + 1); que.push(pair<int, int>(nx, ny)); } que.pop(); } cout << ans << endl; return 0; }
[ "literal.string.change", "control_flow.branch.if.condition.change" ]
868,653
868,654
u110383054
cpp
p03053
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int H, W; cin >> H >> W; vector<string> s(H); for (int i = 0; i < H; i++) cin >> s[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i][j] == '.') { que.push(pair<int, int>(i, j)); dist[i][j] = 0; } } } int ans = 0; while (!que.empty()) { pair<int, int> v = que.front(); for (int i = 0; i < 4; i++) { int nx = v.first + dx[i]; int ny = v.second + dy[i]; if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1) continue; ans = (dist[nx][ny] = dist[v.first][v.second] + 1); que.push(pair<int, int>(nx, ny)); } que.pop(); } cout << ans << endl; return 0; }
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int H, W; cin >> H >> W; vector<string> s(H); for (int i = 0; i < H; i++) cin >> s[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i][j] == '#') { que.push(pair<int, int>(i, j)); dist[i][j] = 0; } } } int ans = 0; while (!que.empty()) { pair<int, int> v = que.front(); for (int i = 0; i < 4; i++) { int nx = v.first + dx[i]; int ny = v.second + dy[i]; if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1) continue; ans = dist[nx][ny] = dist[v.first][v.second] + 1; que.push(pair<int, int>(nx, ny)); } que.pop(); } cout << ans << endl; return 0; }
[ "literal.string.change", "control_flow.branch.if.condition.change" ]
868,653
868,655
u110383054
cpp
p03053
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() // sort(all(vi S)) sort(all(string S)) #define push_back pb #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } using P = pair<int, int>; // P.first, P.second typedef long long ll; typedef vector<int> vi; typedef set<int> seti; typedef vector<string> vs; const int MOD = 1e9 + 7; const int INF = 1e9; int H, W; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int dist[1005][1005]; bool in(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } int main() { cin >> H >> W; vs A(H); queue<P> Q; rep(i, H) cin >> A[i]; rep(i, H) rep(j, W) { dist[i][j] = -1; if (A[i][j] == '#') { Q.push({i, j}); dist[i][j] = 0; } } while (!Q.empty()) { P p = Q.front(); Q.pop(); int x = p.first, y = p.second; rep(i, 3) { int nx = x + dx[i], ny = y + dy[i]; if (!in(nx, ny) || dist[nx][ny] != -1) continue; dist[nx][ny] = dist[x][y] + 1; Q.push({nx, ny}); } } 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, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() // sort(all(vi S)) sort(all(string S)) #define push_back pb #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } using P = pair<int, int>; // P.first, P.second typedef long long ll; typedef vector<int> vi; typedef set<int> seti; typedef vector<string> vs; const int MOD = 1e9 + 7; const int INF = 1e9; int H, W; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int dist[1005][1005] = {}; bool in(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } int main() { cin >> H >> W; vs A(H); queue<P> Q; rep(i, H) cin >> A[i]; rep(i, H) rep(j, W) { dist[i][j] = -1; if (A[i][j] == '#') { Q.push({i, j}); dist[i][j] = 0; } } while (!Q.empty()) { P p = Q.front(); Q.pop(); int x = p.first, y = p.second; rep(i, 4) { int nx = x + dx[i], ny = y + dy[i]; if (!in(nx, ny) || dist[nx][ny] != -1) continue; dist[nx][ny] = dist[x][y] + 1; Q.push({nx, ny}); } } int ans = 0; rep(i, H) rep(j, W) { ans = max(ans, dist[i][j]); } cout << ans << endl; }
[ "variable_declaration.value.change", "literal.number.change", "call.arguments.change" ]
868,674
868,675
u106297876
cpp
p03053
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using itn = int; using namespace std; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int H, W; cin >> H >> W; string A[H]; rep(i, H) cin >> A[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; rep(y, H) { rep(x, W) { if (A[x][y] == '#') { dist.at(y).at(x) = 0; que.push(mp(y, x)); } } } while (!que.empty()) { pair<int, int> n = que.front(); que.pop(); rep(i, 4) { int nx = n.S + dx[i], ny = n.F + dy[i]; if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue; if (dist.at(ny).at(nx) >= 0) continue; dist.at(ny).at(nx) = dist.at(n.F).at(n.S) + 1; que.push(mp(ny, nx)); } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, dist.at(i).at(j)); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using itn = int; using namespace std; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int H, W; cin >> H >> W; string A[H]; rep(i, H) cin >> A[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; rep(y, H) { rep(x, W) { if (A[y][x] == '#') { dist.at(y).at(x) = 0; que.push(mp(y, x)); } } } while (!que.empty()) { pair<int, int> n = que.front(); que.pop(); rep(i, 4) { int nx = n.S + dx[i], ny = n.F + dy[i]; if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue; if (dist.at(ny).at(nx) >= 0) continue; dist.at(ny).at(nx) = dist.at(n.F).at(n.S) + 1; que.push(mp(ny, nx)); } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, dist.at(i).at(j)); } } cout << ans << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
868,686
868,687
u089885969
cpp
p03053
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using itn = int; using namespace std; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int H, W; cin >> H >> W; string A[H]; rep(i, H) cin >> A[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; rep(y, H) { rep(x, W) { if (A[x][y] == '#') { dist.at(y).at(x) = 0; que.push(mp(y, x)); } } } while (!que.empty()) { pair<int, int> n = que.front(); que.pop(); rep(i, 4) { int nx = n.S + dx[i], ny = n.F + dy[i]; if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue; if (dist.at(ny).at(nx) >= 0) continue; if (A[ny][nx] == '#') continue; dist.at(ny).at(nx) = dist.at(n.F).at(n.S) + 1; que.push(mp(ny, nx)); } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, dist.at(i).at(j)); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using itn = int; using namespace std; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { int H, W; cin >> H >> W; string A[H]; rep(i, H) cin >> A[i]; vector<vector<int>> dist(H, vector<int>(W, -1)); queue<pair<int, int>> que; rep(y, H) { rep(x, W) { if (A[y][x] == '#') { dist.at(y).at(x) = 0; que.push(mp(y, x)); } } } while (!que.empty()) { pair<int, int> n = que.front(); que.pop(); rep(i, 4) { int nx = n.S + dx[i], ny = n.F + dy[i]; if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue; if (dist.at(ny).at(nx) >= 0) continue; if (A[ny][nx] == '#') continue; dist.at(ny).at(nx) = dist.at(n.F).at(n.S) + 1; que.push(mp(ny, nx)); } } int ans = 0; rep(i, H) { rep(j, W) { ans = max(ans, dist.at(i).at(j)); } } cout << ans << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
868,688
868,689
u089885969
cpp