problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02854
C++
Runtime Error
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { #ifdef DEBUG freopen("input.txt", "r", stdin); #else // freopen("zalupa.in","r",stdin); // freopen("zalupa.out","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); cout << fixed; ll sum = 0; int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } int part = 0; int part2 = 0; int i = 0; while (part * 2 < sum) { if ((part + a[i]) * 2 >= sum) { part2 = part; } part += a[i]; ++i; } cout << min(2 * part - sum, sum - 2 * part2); return 0; }
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { #ifdef DEBUG freopen("input.txt", "r", stdin); #else // freopen("zalupa.in","r",stdin); // freopen("zalupa.out","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); cout << fixed; ll sum = 0; int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } ll part = 0; ll part2 = 0; int i = 0; while (part * 2 < sum) { if ((part + a[i]) * 2 >= sum) { part2 = part; } part += a[i]; ++i; } cout << min(2 * part - sum, sum - 2 * part2); return 0; }
replace
29
31
29
31
0
p02854
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[100005]; int main() { int n; cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } ll sum1 = 0; ll ans = sum; for (int i = 0; i < n; i++) { sum1 += a[i]; ans = min(ans, abs(sum - sum1 * 2)); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[200005]; int main() { int n; cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } ll sum1 = 0; ll ans = sum; for (int i = 0; i < n; i++) { sum1 += a[i]; ans = min(ans, abs(sum - sum1 * 2)); } cout << ans << '\n'; }
replace
3
4
3
4
0
p02854
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #define dumpv(...) #endif #define rep(i, n) for (int i = 0; i < (n); i++) #define mins(x, y) (x = min(x, y)) #define maxs(x, y) (x = max(x, y)) typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; const int MOD = 1e9 + 7; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; void solve() { int n; cin >> n; vl a(n); rep(i, n) cin >> a[i]; vl acc(n + 1); acc[0] = 0; rep(i, n) acc[i + 1] = acc[i] + a[i]; dump(a, acc); ll l, r; int m; l = a[0]; r = acc[n] - a[0]; rep(i, n - 1) { if (l >= r) { m = i; break; } l += a[i + 1]; r -= a[i + 1]; dump(l, r); } dump(m); ll d1 = LINF; ll d2 = LINF; l = acc[m + 1]; r = acc[n] - acc[m + 1]; d1 = abs(l - r); dump(l, r, d1); if (m > 0) { l = acc[m]; r = acc[n] - acc[m]; d2 = abs(l - r); dump(l, r, d2); } cout << min(d1, d2) << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // freopen("temp.1", "r", stdin); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #define dumpv(...) #endif #define rep(i, n) for (int i = 0; i < (n); i++) #define mins(x, y) (x = min(x, y)) #define maxs(x, y) (x = max(x, y)) typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; const int MOD = 1e9 + 7; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; void solve() { int n; cin >> n; vl a(n); rep(i, n) cin >> a[i]; vl acc(n + 1); acc[0] = 0; rep(i, n) acc[i + 1] = acc[i] + a[i]; dump(a, acc); ll l, r; int m = 0; l = a[0]; r = acc[n] - a[0]; rep(i, n - 1) { if (l >= r) { m = i; break; } l += a[i + 1]; r -= a[i + 1]; dump(l, r); } dump(m); ll d1 = LINF; ll d2 = LINF; l = acc[m + 1]; r = acc[n] - acc[m + 1]; d1 = abs(l - r); dump(l, r, d1); if (m > 0) { l = acc[m]; r = acc[n] - acc[m]; d2 = abs(l - r); dump(l, r, d2); } cout << min(d1, d2) << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // freopen("temp.1", "r", stdin); solve(); return 0; }
replace
33
34
33
34
0
p02854
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #define int long long #define mod 1000000007 #define for0(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= (n); i++) using namespace std; signed main() { int n; cin >> n; int a[123456]; a[0] = 0; for1(i, n) { cin >> a[i]; a[i] += a[i - 1]; } int ans = a[n] * 2; for1(i, n) ans = min(ans, abs(2 * a[i] - a[n])); cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #define int long long #define mod 1000000007 #define for0(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= (n); i++) using namespace std; signed main() { int n; cin >> n; int a[223456]; a[0] = 0; for1(i, n) { cin >> a[i]; a[i] += a[i - 1]; } int ans = a[n] * 2; for1(i, n) ans = min(ans, abs(2 * a[i] - a[n])); cout << ans << endl; }
replace
12
13
12
13
0
p02854
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int64_t> B(N + 1); B.at(0) = 0; for (int i = 0; i <= N; i++) B.at(i) = B.at(i - 1) + A.at(i - 1); int64_t a = B.at(N) / 2; auto itr = lower_bound(B.begin(), B.end(), a); int k = distance(B.begin(), itr); int64_t ans = max(B.at(k - 1), B.at(N) - B.at(k)); ans = B.at(N) - 2 * ans; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int64_t> B(N + 1); B.at(0) = 0; for (int i = 1; i <= N; i++) B.at(i) = B.at(i - 1) + A.at(i - 1); int64_t a = B.at(N) / 2; auto itr = lower_bound(B.begin(), B.end(), a); int k = distance(B.begin(), itr); int64_t ans = max(B.at(k - 1), B.at(N) - B.at(k)); ans = B.at(N) - 2 * ans; cout << ans << endl; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 4)
p02854
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; const int N = (int)1e5 + 5; int n, a[N], sum[N]; void init() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sum[0] = 0; for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i]; } void solve() { int ans = 1e18; for (int i = 1; i < n; ++i) { ans = min(ans, abs(sum[i] - (sum[n] - sum[i]))); } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); init(); solve(); }
#include <bits/stdc++.h> #define int long long using namespace std; const int N = (int)2e5 + 5; int n, a[N], sum[N]; void init() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sum[0] = 0; for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i]; } void solve() { int ans = 1e18; for (int i = 1; i < n; ++i) { ans = min(ans, abs(sum[i] - (sum[n] - sum[i]))); } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); init(); solve(); }
replace
4
5
4
5
0
p02854
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define ep emplace #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define semicolon ; #define ryan bear using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; const int inf = 1e9 + 7; const ll INF = 1e18; ll n, i, s, S, M; ll a[20010]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (i = 0; i < n; i++) cin >> a[i], s += a[i]; M = INF; for (i = 0; i < n; i++) S += a[i], M = min(M, abs(s - 2 * S)); cout << M << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define ep emplace #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define semicolon ; #define ryan bear using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; const int inf = 1e9 + 7; const ll INF = 1e18; ll n, i, s, S, M; ll a[200010]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (i = 0; i < n; i++) cin >> a[i], s += a[i]; M = INF; for (i = 0; i < n; i++) S += a[i], M = min(M, abs(s - 2 * S)); cout << M << endl; return 0; }
replace
17
18
17
18
0
p02854
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> b(n + 1, 0); for (int i = 0; i <= n; i++) { b[i + 1] = b[i]; b[i + 1] += a[i]; } long long ans = 90000000000; long long min; for (int i = 0; i <= n - 1; i++) { min = abs((b[n] - b[i + 1]) - (b[i + 1] - b[0])); if (min < ans) ans = min; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> b(n + 1, 0); for (int i = 0; i < n; i++) { b[i + 1] = b[i]; b[i + 1] += a[i]; } long long ans = 90000000000; long long min; for (int i = 0; i <= n - 1; i++) { min = abs((b[n] - b[i + 1]) - (b[i + 1] - b[0])); if (min < ans) ans = min; } cout << ans << endl; }
replace
11
12
11
12
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, k; cin >> h >> w >> k; vector<vector<char>> a(h, vector<char>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a.at(i).at(j); } } vector<vector<int>> x(h, vector<int>(w)); vector<bool> exist(h, false); int now = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (exist.at(i) && a.at(i).at(j) == '#') x.at(i).at(j) = 1; if (a.at(i).at(j) == '#') exist.at(i) = true; } } for (int i = 0; i < h; i++) { if (exist.at(i)) { x.at(i).at(0) = now; for (int j = 1; j < w; j++) { x.at(i).at(j) += x.at(i).at(j - 1); } now = x.at(i).at(w - 1) + 1; } } for (int i = 1; i < h; i++) { if (exist.at(i - 1) == true && exist.at(i) == false) { for (int j = 0; j < w; j++) { x.at(i).at(j) = x.at(i - 1).at(j); } exist.at(i) = true; } } for (int i = h - 1; i <= 0; i--) { if (exist.at(i + 1) == true && exist.at(i) == false) { for (int j = 0; j < w; j++) { x.at(i).at(j) = x.at(i + 1).at(j); } exist.at(i) = true; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j) cout << " "; cout << x.at(i).at(j); } cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, k; cin >> h >> w >> k; vector<vector<char>> a(h, vector<char>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a.at(i).at(j); } } vector<vector<int>> x(h, vector<int>(w)); vector<bool> exist(h, false); int now = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (exist.at(i) && a.at(i).at(j) == '#') x.at(i).at(j) = 1; if (a.at(i).at(j) == '#') exist.at(i) = true; } } for (int i = 0; i < h; i++) { if (exist.at(i)) { x.at(i).at(0) = now; for (int j = 1; j < w; j++) { x.at(i).at(j) += x.at(i).at(j - 1); } now = x.at(i).at(w - 1) + 1; } } for (int i = 1; i < h; i++) { if (exist.at(i - 1) == true && exist.at(i) == false) { for (int j = 0; j < w; j++) { x.at(i).at(j) = x.at(i - 1).at(j); } exist.at(i) = true; } } for (int i = h - 2; i >= 0; i--) { if (exist.at(i + 1) == true && exist.at(i) == false) { for (int j = 0; j < w; j++) { x.at(i).at(j) = x.at(i + 1).at(j); } exist.at(i) = true; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j) cout << " "; cout << x.at(i).at(j); } cout << "\n"; } }
replace
47
48
47
48
0
p02855
Python
Runtime Error
H, W, K = map(int, input().split()) c = [] cnt = [0] * W num = 0 A = [[0] * W for _ in range(H)] for i in range(H): row = list(input()) c.append(row) cnt[i] = row.count("#") def solve(cl, cr): global num P = [] for i in range(cl, cr + 1): for j in range(W): if c[i][j] == "#": P.append(j) P = sorted(P) for i in range(len(P)): v1 = 0 v2 = W - 1 if i >= 1: v1 = P[i - 1] + 1 if i < len(P) - 1: v2 = P[i] num += 1 for j in range(cl, cr + 1): for k in range(v1, v2 + 1): A[j][k] = num vec = [] for i in range(H): if cnt[i] >= 1: vec.append(i) for i in range(len(vec)): v1 = 0 v2 = H - 1 if i >= 1: v1 = vec[i - 1] + 1 if i < len(vec) - 1: v2 = vec[i] solve(v1, v2) for i in range(H): print(*A[i])
H, W, K = map(int, input().split()) c = [] cnt = [0] * H num = 0 A = [[0] * W for _ in range(H)] for i in range(H): row = list(input()) c.append(row) cnt[i] = row.count("#") def solve(cl, cr): global num P = [] for i in range(cl, cr + 1): for j in range(W): if c[i][j] == "#": P.append(j) P = sorted(P) for i in range(len(P)): v1 = 0 v2 = W - 1 if i >= 1: v1 = P[i - 1] + 1 if i < len(P) - 1: v2 = P[i] num += 1 for j in range(cl, cr + 1): for k in range(v1, v2 + 1): A[j][k] = num vec = [] for i in range(H): if cnt[i] >= 1: vec.append(i) for i in range(len(vec)): v1 = 0 v2 = H - 1 if i >= 1: v1 = vec[i - 1] + 1 if i < len(vec) - 1: v2 = vec[i] solve(v1, v2) for i in range(H): print(*A[i])
replace
2
3
2
3
0
p02855
C++
Runtime Error
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #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 rev(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for (int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; /* ----------------よく使う数字や配列----------------- */ int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr int inf = INT32_MAX / 2; constexpr ll INF = LLONG_MAX / 2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; /* ----------------------end----------------------- */ /* --------------------テンプレート------------------ */ template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /* ----------------------end----------------------- */ /* --------------------ライブラリ-------------------- */ ll fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(ll n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { // 各桁の和 ll sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /* ----------------------end----------------------- */ #pragma endregion signed main() { int h, w, k; cin >> h >> w >> k; vvi ans(h, vi(w)); int a = 1; rep(i, h) { rep(j, w) { char c; cin >> c; if (c == '#') { ans[i][j] = a; a++; } else if (j != 0) ans[i][j] = ans[i][j - 1]; } } rep(i, h) if (ans[i][0] == 0) ans[i][0] = ans[i][1]; rep(j, w) { rep(i, h) { if (ans[i][j] == 0) { if (i == 0) ans[i][j] = ans[i + 1][j]; else ans[i][j] = ans[i - 1][j]; } } } rep(i, h) { rep(j, w) { cout << ans[i][j]; if (j == w - 1) cout << endl; else cout << ' '; } } return 0; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #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 rev(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for (int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; /* ----------------よく使う数字や配列----------------- */ int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr int inf = INT32_MAX / 2; constexpr ll INF = LLONG_MAX / 2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; /* ----------------------end----------------------- */ /* --------------------テンプレート------------------ */ template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /* ----------------------end----------------------- */ /* --------------------ライブラリ-------------------- */ ll fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(ll n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { // 各桁の和 ll sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /* ----------------------end----------------------- */ #pragma endregion signed main() { int h, w, k; cin >> h >> w >> k; vvi ans(h, vi(w)); int a = 1; rep(i, h) { rep(j, w) { char c; cin >> c; if (c == '#') { ans[i][j] = a; a++; } else if (j != 0) ans[i][j] = ans[i][j - 1]; } } rep(i, h) { rev(j, w - 1) { if (ans[i][j] == 0) ans[i][j] = ans[i][j + 1]; } } rep(x, 300) { rep(j, w) { rep(i, h) { if (ans[i][j] == 0) { if (i == 0) ans[i][j] = ans[i + 1][j]; else ans[i][j] = ans[i - 1][j]; } } } } rep(x, 300) { rep(j, w) { rev(i, h) { if (ans[i][j] == 0) { if (i == h - 1) ans[i][j] = ans[i - 1][j]; else ans[i][j] = ans[i + 1][j]; } } } } rep(i, h) { rep(j, w) { cout << ans[i][j]; if (j == w - 1) cout << endl; else cout << ' '; } } return 0; }
replace
96
104
96
123
0
p02855
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 11451419194545; int main() { ll H, W, K; cin >> H >> W >> K; vector<pii> in; vector<vector<ll>> grid(H, vector<ll>(W, -1)); ll cn = 1; for (ll row = 0; row < H; row++) { for (ll col = 0; col < W; col++) { char t = 0; cin >> t; if (t == '#') { grid[row][col] = cn; in.push_back(make_pair(make_pair(row, col), cn)); cn++; } } } bool f = 0; // cout << "ok" << endl; for (ll i = 0; i < in.size(); i++) { // cout << in[i].first.first << " " << in[i].first.second << endl; // 左 ll row = in[i].first.first; ll col = in[i].first.second; for (ll left = col - 1; left >= 0; left--) { if (grid[row][left] != -1) break; grid[row][left] = in[i].second; } // 右 for (ll right = col + 1; right < W; right++) { if (grid[row][right] != -1) break; grid[row][right] = in[i].second; } } // 確認 for (ll col = 0; col < W; col++) { for (ll row = 0; row < H; row++) { if (grid[row][col] == -1) continue; // うえ for (ll up = row - 1; up >= 0; up--) { if (grid[up][col] != -1) break; grid[up][col] = grid[up + 1][col]; } // した for (ll down = row + 1; down >= 0; down--) { if (grid[down][col] != -1) break; grid[down][col] = grid[down - 1][col]; } } } for (ll row = 0; row < H; row++) { for (ll col = 0; col < W; col++) { cout << (col ? " " : "") << grid[row][col]; } cout << endl; } }
#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 11451419194545; int main() { ll H, W, K; cin >> H >> W >> K; vector<pii> in; vector<vector<ll>> grid(H, vector<ll>(W, -1)); ll cn = 1; for (ll row = 0; row < H; row++) { for (ll col = 0; col < W; col++) { char t = 0; cin >> t; if (t == '#') { grid[row][col] = cn; in.push_back(make_pair(make_pair(row, col), cn)); cn++; } } } bool f = 0; // cout << "ok" << endl; for (ll i = 0; i < in.size(); i++) { // cout << in[i].first.first << " " << in[i].first.second << endl; // 左 ll row = in[i].first.first; ll col = in[i].first.second; for (ll left = col - 1; left >= 0; left--) { if (grid[row][left] != -1) break; grid[row][left] = in[i].second; } // 右 for (ll right = col + 1; right < W; right++) { if (grid[row][right] != -1) break; grid[row][right] = in[i].second; } } // 確認 for (ll col = 0; col < W; col++) { for (ll row = 0; row < H; row++) { if (grid[row][col] == -1) continue; // うえ for (ll up = row - 1; up >= 0; up--) { if (grid[up][col] != -1) break; grid[up][col] = grid[up + 1][col]; } // した for (ll down = row + 1; down < H; down++) { if (grid[down][col] != -1) break; grid[down][col] = grid[down - 1][col]; } } } for (ll row = 0; row < H; row++) { for (ll col = 0; col < W; col++) { cout << (col ? " " : "") << grid[row][col]; } cout << endl; } }
replace
69
70
69
70
-11
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; int main() { int h, w, k, f = 0; bool flag; cin >> h >> w >> k; vector<vector<int>> sss(h, vector<int>(w)); vector<int> a(k), b(k); char x; rep(i, h) { flag = false; rep(j, w) { cin >> x; if (x == '#') { a[f] = i; b[f] = j; f++; if (!flag) { rep(t, j) sss[i][t] = f; } flag = true; } if (flag) { sss[i][j] = f; } } } for (int i = a[0] + 1; i < h; i++) { rep(j, w) { if (sss[i][j] == 0) sss[i][j] = sss[i - 1][j]; } } for (int i = a[0] - 1; i >= 0; i--) { rep(j, w) { if (sss[i][j] == 0) sss[i][j] = sss[i - 1][j]; } } rep(i, h) { rep(j, w) cout << sss[i][j] << ' '; cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; int main() { int h, w, k, f = 0; bool flag; cin >> h >> w >> k; vector<vector<int>> sss(h, vector<int>(w)); vector<int> a(k), b(k); char x; rep(i, h) { flag = false; rep(j, w) { cin >> x; if (x == '#') { a[f] = i; b[f] = j; f++; if (!flag) { rep(t, j) sss[i][t] = f; } flag = true; } if (flag) { sss[i][j] = f; } } } for (int i = a[0] + 1; i < h; i++) { rep(j, w) { if (sss[i][j] == 0) sss[i][j] = sss[i - 1][j]; } } for (int i = a[0] - 1; i >= 0; i--) { rep(j, w) { if (sss[i][j] == 0) sss[i][j] = sss[i + 1][j]; } } rep(i, h) { rep(j, w) cout << sss[i][j] << ' '; cout << endl; } }
replace
39
40
39
40
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using P = pair<ll, ll>; template <class T> using V = vector<T>; const ll MAX = 1e9; int main() { int h, w, k; cin >> h >> w >> k; V<string> c(h); rep(i, h) cin >> c[i]; V<V<int>> ans(h, V<int>(w, 0)); int s = 0; rep(i, h) { if (c[i].find("#") != c[i].npos) { s = i; break; } } int n = 0; for (int i = s; i < h; i++) { if (c[i].find("#") == c[i].npos) { c[i] = c[i - 1]; continue; } n++; int f = c[i].find("#"); rep(j, f + 1) ans[i][j] = n; for (int j = f + 1; j < w; j++) { if (c[i][j] == '#') n++; ans[i][j] = n; } } for (int i = h - 1; i >= 0; i--) { if (ans[i][0] == 0) ans[i] = ans[i + 1]; } rep(i, h) { rep(j, w) printf("%d ", ans[i][j]); printf("\n"); } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using P = pair<ll, ll>; template <class T> using V = vector<T>; const ll MAX = 1e9; int main() { int h, w, k; cin >> h >> w >> k; V<string> c(h); rep(i, h) cin >> c[i]; V<V<int>> ans(h, V<int>(w, 0)); int s = 0; rep(i, h) { if (c[i].find("#") != c[i].npos) { s = i; break; } } int n = 0; for (int i = s; i < h; i++) { if (c[i].find("#") == c[i].npos) { ans[i] = ans[i - 1]; continue; } n++; int f = c[i].find("#"); rep(j, f + 1) ans[i][j] = n; for (int j = f + 1; j < w; j++) { if (c[i][j] == '#') n++; ans[i][j] = n; } } for (int i = h - 1; i >= 0; i--) { if (ans[i][0] == 0) ans[i] = ans[i + 1]; } rep(i, h) { rep(j, w) printf("%d ", ans[i][j]); printf("\n"); } }
replace
27
28
27
28
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; constexpr int64_t mod = 1e9 + 7; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (auto &&e : s) { cin >> e; } vector<vector<int>> number(h, vector<int>(w, 0)); int cnt = 1; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { number[i][j] = cnt; if (s[i][j] == '#') cnt++; } if (s[i][w - 1] == '.') { for (int j = 0; j < w; ++j) { if (number[i][j] == cnt) number[i][j]--; } } cnt = number[i][w - 1] + 1; } vector<int> no_hash; for (int i = 0; i < h; ++i) { bool flag = true; for (int j = 0; j < w; ++j) { if (s[i][j] == '#') flag = false; } if (flag) { no_hash.push_back(i); } } if (*no_hash.rbegin() == h - 1) { int tmp = h - 1; while (tmp != 0) { tmp--; if (!binary_search(no_hash.begin(), no_hash.end(), tmp)) { break; } } while (tmp != h - 1) { tmp++; for (int j = 0; j < w; ++j) { number[tmp][j] = number[tmp - 1][j]; } } } for (int i = 0; i < no_hash.size(); ++i) { int tmp = no_hash[i]; while (tmp != h - 1) { tmp++; if (!binary_search(no_hash.begin(), no_hash.end(), tmp)) { break; } } while (tmp != no_hash[i]) { tmp--; for (int j = 0; j < w; ++j) { number[tmp][j] = number[tmp + 1][j]; } } } // output for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cout << number[i][j] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; constexpr int64_t mod = 1e9 + 7; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (auto &&e : s) { cin >> e; } vector<vector<int>> number(h, vector<int>(w, 0)); int cnt = 1; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { number[i][j] = cnt; if (s[i][j] == '#') cnt++; } if (s[i][w - 1] == '.') { for (int j = 0; j < w; ++j) { if (number[i][j] == cnt) number[i][j]--; } } cnt = number[i][w - 1] + 1; } vector<int> no_hash; for (int i = 0; i < h; ++i) { bool flag = true; for (int j = 0; j < w; ++j) { if (s[i][j] == '#') flag = false; } if (flag) { no_hash.push_back(i); } } if (!no_hash.empty() && *no_hash.rbegin() == h - 1) { int tmp = h - 1; while (tmp != 0) { tmp--; if (!binary_search(no_hash.begin(), no_hash.end(), tmp)) { break; } } while (tmp != h - 1) { tmp++; for (int j = 0; j < w; ++j) { number[tmp][j] = number[tmp - 1][j]; } } } for (int i = 0; i < no_hash.size(); ++i) { int tmp = no_hash[i]; while (tmp != h - 1) { tmp++; if (!binary_search(no_hash.begin(), no_hash.end(), tmp)) { break; } } while (tmp != no_hash[i]) { tmp--; for (int j = 0; j < w; ++j) { number[tmp][j] = number[tmp + 1][j]; } } } // output for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cout << number[i][j] << " "; } cout << endl; } }
replace
40
41
40
41
-11
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } vector<vector<int>> num(h, vector<int>(w, 0)); int now = 1, okheight; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') break; if (j == w - 1) { for (int k = 0; k < w; k++) { num[i][k] = -1; } } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (num[i][j] == -1) break; okheight = i; while (s[i][j] == '.' && j < w) { num[i][j] = now; j++; } if (j != w && s[i][j] == '#') { num[i][j] = now; j++; } while (s[i][j] == '.' && j < w) { num[i][j] = now; j++; } j--; now++; } } int count = 1; while (count > 0) { count = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (num[i][j] != -1) break; count++; if (i != okheight) { num[i][j] = num[i + 1][j]; } else { num[i][j] = num[i - 1][j]; } } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w - 1; j++) { cout << num[i][j] << ' '; } cout << num[i][w - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } vector<vector<int>> num(h, vector<int>(w, 0)); int now = 1, okheight; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') break; if (j == w - 1) { for (int k = 0; k < w; k++) { num[i][k] = -1; } } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (num[i][j] == -1) break; okheight = i; while (s[i][j] == '.' && j < w) { num[i][j] = now; j++; } if (j != w && s[i][j] == '#') { num[i][j] = now; j++; } while (s[i][j] == '.' && j < w) { num[i][j] = now; j++; } j--; now++; } } int count = 1; while (count > 0) { count = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (num[i][j] != -1) break; count++; if (i < okheight) { num[i][j] = num[i + 1][j]; } else { num[i][j] = num[i - 1][j]; } } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w - 1; j++) { cout << num[i][j] << ' '; } cout << num[i][w - 1] << endl; } }
replace
52
53
52
53
0
p02855
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 305; int h, w, k; char mat[N][N]; int ans[N][N]; int main() { scanf("%d %d %d", &h, &w, &k); for (int i = 0; i < h; i++) scanf(" %s", mat[i]); int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int tmp = j; while (tmp < w and mat[i][tmp] != '#') tmp++; if (tmp == w) { if (j == 0) break; while (j < w) ans[i][j++] = cnt; } else { cnt++; while (j <= tmp) ans[i][j++] = cnt; j = tmp; } } } while (1) { bool any = false; for (int i = 0; i < h; i++) { if (ans[i][0] == 0) { any = true; int add = i + 1 < h ? 1 : -1; for (int j = 0; j < w; j++) { ans[i][j] = ans[i + add][j]; } } } if (!any) break; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { printf("%d%c", ans[i][j], " \n"[j + 1 == w]); } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 305; int h, w, k; char mat[N][N]; int ans[N][N]; int main() { scanf("%d %d %d", &h, &w, &k); for (int i = 0; i < h; i++) scanf(" %s", mat[i]); int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int tmp = j; while (tmp < w and mat[i][tmp] != '#') tmp++; if (tmp == w) { if (j == 0) break; while (j < w) ans[i][j++] = cnt; } else { cnt++; while (j <= tmp) ans[i][j++] = cnt; j = tmp; } } } while (1) { bool any = false; for (int i = 0; i < h; i++) { if (ans[i][0] == 0) { any = true; int add = i + 1 < h ? 1 : -1; if (ans[i + add][0] == 0) { add *= -1; if (i + add < 0 or i + add >= h) continue; if (ans[i + add][0] == 0) continue; } for (int j = 0; j < w; j++) { ans[i][j] = ans[i + add][j]; } } } if (!any) break; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { printf("%d%c", ans[i][j], " \n"[j + 1 == w]); } } }
insert
43
43
43
50
TLE
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int contains(string s) { for (int i = 0; i < s.size(); ++i) { if (s[i] == '#') { return 1; } } return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int H, W, K; cin >> H >> W >> K; vector<vector<int>> res(H, vector<int>(W)); vector<string> s(H); int y = 0; for (int i = 0; i < H; ++i) { cin >> s[i]; if (contains(s[i])) { ++y; } bool flag = 0; for (int j = 0; j < W; ++j) { if (s[i][j] == '#') { if (flag) { ++y; } flag = true; } res[i][j] = y; } } for (int i = 1; i < H; ++i) { if (!contains(s[i])) { res[i] = res[i - 1]; } } for (int i = H - 1; i >= 0; --i) { if (!contains(s[i])) { res[i] = res[i + 1]; } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cout << res[i][j] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int contains(string s) { for (int i = 0; i < s.size(); ++i) { if (s[i] == '#') { return 1; } } return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int H, W, K; cin >> H >> W >> K; vector<vector<int>> res(H, vector<int>(W)); vector<string> s(H); int y = 0; for (int i = 0; i < H; ++i) { cin >> s[i]; if (contains(s[i])) { ++y; } bool flag = 0; for (int j = 0; j < W; ++j) { if (s[i][j] == '#') { if (flag) { ++y; } flag = true; } res[i][j] = y; } } for (int i = 1; i < H; ++i) { if (!contains(s[i])) { res[i] = res[i - 1]; } } for (int i = H - 2; i >= 0; --i) { if (!contains(s[i])) { res[i] = res[i + 1]; } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cout << res[i][j] << " "; } cout << endl; } return 0; }
replace
42
43
42
43
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, K; cin >> H >> W >> K; vector<string> s(H); for (int i = 0; i < H; i++) { cin >> s[i]; } int num = 0; vector<vector<int>> ans(H, vector<int>(K, 0)); for (int i = 0; i < H; i++) { vector<int> v; for (int j = 0; j < W; j++) { if (s[i][j] == '#') { v.push_back(j); } } if (v.empty()) { if (i == 0 || ans[i - 1][0] == 0) continue; for (int j = 0; j < W; j++) { ans[i][j] = ans[i - 1][j]; } } else { int j = 0; for (int idx = 0; idx < v.size(); idx++) { num++; while (j <= v[idx]) { ans[i][j] = num; j++; } } while (j < W) { ans[i][j] = num; j++; } } } for (int i = H - 2; i >= 0; i--) { if (ans[i][0] == 0) { for (int j = 0; j < W; j++) { ans[i][j] = ans[i + 1][j]; } } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cout << ans[i][j] << " \n"[j + 1 == W]; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, K; cin >> H >> W >> K; vector<string> s(H); for (int i = 0; i < H; i++) { cin >> s[i]; } int num = 0; vector<vector<int>> ans(H, vector<int>(W, 0)); for (int i = 0; i < H; i++) { vector<int> v; for (int j = 0; j < W; j++) { if (s[i][j] == '#') { v.push_back(j); } } if (v.empty()) { if (i == 0 || ans[i - 1][0] == 0) continue; for (int j = 0; j < W; j++) { ans[i][j] = ans[i - 1][j]; } } else { int j = 0; for (int idx = 0; idx < v.size(); idx++) { num++; while (j <= v[idx]) { ans[i][j] = num; j++; } } while (j < W) { ans[i][j] = num; j++; } } } for (int i = H - 2; i >= 0; i--) { if (ans[i][0] == 0) { for (int j = 0; j < W; j++) { ans[i][j] = ans[i + 1][j]; } } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cout << ans[i][j] << " \n"[j + 1 == W]; } } return 0; }
replace
17
18
17
18
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; char Grid[110][110]; int Ans[110][110], P; int main() { int H, W, K; cin >> H >> W >> K; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> Grid[i][j]; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (Grid[i][j] == '#') { P++; Ans[i][j] = P; for (int k = i - 1; k >= 0 && Ans[k][j] == 0 && Grid[k][j] != '#'; k--) Ans[k][j] = P; for (int k = i + 1; k < H && Ans[k][j] == 0 && Grid[k][j] != '#'; k++) Ans[k][j] = P; } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (Ans[i][j] == 0) { int k; for (k = j - 1; k >= 0 && Ans[i][k] == 0; k--) ; // cout<<i<<" "<<j<<" "<<k<<endl; if (k != -1) Ans[i][j] = Ans[i][k]; else { for (k = j + 1; k < W && Ans[i][k] == 0; k++) ; Ans[i][j] = Ans[i][k]; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cout << Ans[i][j] << " "; puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; char Grid[310][310]; int Ans[310][310], P; int main() { int H, W, K; cin >> H >> W >> K; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> Grid[i][j]; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (Grid[i][j] == '#') { P++; Ans[i][j] = P; for (int k = i - 1; k >= 0 && Ans[k][j] == 0 && Grid[k][j] != '#'; k--) Ans[k][j] = P; for (int k = i + 1; k < H && Ans[k][j] == 0 && Grid[k][j] != '#'; k++) Ans[k][j] = P; } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (Ans[i][j] == 0) { int k; for (k = j - 1; k >= 0 && Ans[i][k] == 0; k--) ; // cout<<i<<" "<<j<<" "<<k<<endl; if (k != -1) Ans[i][j] = Ans[i][k]; else { for (k = j + 1; k < W && Ans[i][k] == 0; k++) ; Ans[i][j] = Ans[i][k]; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cout << Ans[i][j] << " "; puts(""); } return 0; }
replace
2
4
2
4
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back using namespace std; using ll = long long; using ii = pair<int, int>; const int N = 305; int ans[N][N]; int main() { int h, w, _; char mat[N][N]; scanf("%d %d %d", &h, &w, &_); for (int i = 0; i < h; i++) { scanf("%s", mat[i]); } int id = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (mat[i][j] == '#') { int up = i, down = i; ans[i][j] = id; while (up > 0 && mat[up - 1][j] == '.' && ans[up - 1][j] == 0) { up--; ans[up][j] = id; } while (down < h - 1 && mat[down + 1][j] == '.' && ans[down + 1][j] == 0) { down++; ans[down][j] = id; } for (int k = j - 1; k >= 0; k--) { int up2 = i, down2 = i; if (ans[i][k] != 0 || mat[i][k] != '.') break; while (up2 > up && mat[up2 - 1][k] == '.' && ans[up2 - 1][k] == 0) { up2--; } while (down2 < down && mat[down2 + 1][k] == '.' && ans[down2 + 1][k] == 0) { down2++; } if (up2 != up || down2 != down) { break; } for (int l = up2; l <= down2; l++) { ans[l][k] = id; } } for (int k = j + 1; k < w; k++) { int up2 = i, down2 = i; if (ans[i][k] != 0 || mat[i][k] != '.') break; while (up2 > up && mat[up2 - 1][k] == '.' && ans[up2 - 1][k] == 0) { up2--; } while (down2 < down && mat[down2 + 1][k] == '.' && ans[down2 + 1][k] == 0) { down2++; } if (up2 != up || down2 != down) { break; } for (int l = up2; l <= down2; l++) { ans[l][k] = id; } } id++; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { assert(ans[i][j] != 0); printf("%d%c", ans[i][j], j == w - 1 ? '\n' : ' '); } } }
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back using namespace std; using ll = long long; using ii = pair<int, int>; const int N = 305; int ans[N][N]; int main() { int h, w, _; char mat[N][N]; scanf("%d %d %d", &h, &w, &_); for (int i = 0; i < h; i++) { scanf("%s", mat[i]); } int id = 1; for (int j = 0; j < w; j++) { for (int i = 0; i < h; i++) { if (mat[i][j] == '#') { int up = i, down = i; ans[i][j] = id; while (up > 0 && mat[up - 1][j] == '.' && ans[up - 1][j] == 0) { up--; ans[up][j] = id; } while (down < h - 1 && mat[down + 1][j] == '.' && ans[down + 1][j] == 0) { down++; ans[down][j] = id; } for (int k = j - 1; k >= 0; k--) { int up2 = i, down2 = i; if (ans[i][k] != 0 || mat[i][k] != '.') break; while (up2 > up && mat[up2 - 1][k] == '.' && ans[up2 - 1][k] == 0) { up2--; } while (down2 < down && mat[down2 + 1][k] == '.' && ans[down2 + 1][k] == 0) { down2++; } if (up2 != up || down2 != down) { break; } for (int l = up2; l <= down2; l++) { ans[l][k] = id; } } for (int k = j + 1; k < w; k++) { int up2 = i, down2 = i; if (ans[i][k] != 0 || mat[i][k] != '.') break; while (up2 > up && mat[up2 - 1][k] == '.' && ans[up2 - 1][k] == 0) { up2--; } while (down2 < down && mat[down2 + 1][k] == '.' && ans[down2 + 1][k] == 0) { down2++; } if (up2 != up || down2 != down) { break; } for (int l = up2; l <= down2; l++) { ans[l][k] = id; } } id++; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { assert(ans[i][j] != 0); printf("%d%c", ans[i][j], j == w - 1 ? '\n' : ' '); } } }
replace
21
23
21
23
0
p02855
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int main() { int64_t H, W, K; cin >> H >> W >> K; vector<string> s(H); for (int64_t i = 0; i < H; i++) { cin >> s[i]; } vector<vector<int64_t>> ans(H, vector<int64_t>(W, -1)); int64_t index = 1; for (int64_t i = 0; i < H; i++) { int64_t num = 0; for (int64_t j = 0; j < W; j++) { if (s[i][j] == '#') { num++; } } if (num == 0) { continue; } for (int64_t j = 0; j < W; j++) { ans[i][j] = index; if (s[i][j] == '#') { if (--num > 0) { index++; } } } index++; } for (int64_t i = 0; i < H; i++) { if (ans[i][0] == -1) { (i == 0 ? ans[i] = ans[i + 1] : ans[i] = ans[i - 1]); } } for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { cout << ans[i][j] << " \n"[j == W - 1]; assert(1 <= ans[i][j] && ans[i][j] <= K); } } }
#include "bits/stdc++.h" using namespace std; int main() { int64_t H, W, K; cin >> H >> W >> K; vector<string> s(H); for (int64_t i = 0; i < H; i++) { cin >> s[i]; } vector<vector<int64_t>> ans(H, vector<int64_t>(W, -1)); int64_t index = 1; for (int64_t i = 0; i < H; i++) { int64_t num = 0; for (int64_t j = 0; j < W; j++) { if (s[i][j] == '#') { num++; } } if (num == 0) { continue; } for (int64_t j = 0; j < W; j++) { ans[i][j] = index; if (s[i][j] == '#') { if (--num > 0) { index++; } } } index++; } for (int64_t i = 0; i < H; i++) { if (ans[i][0] == -1) { continue; } for (int64_t ii = i - 1; ii >= 0; ii--) { if (ans[ii][0] == -1) { ans[ii] = ans[i]; } else { break; } } for (int64_t ii = i + 1; ii < H; ii++) { if (ans[ii][0] == -1) { ans[ii] = ans[i]; } else { break; } } } for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { cout << ans[i][j] << " \n"[j == W - 1]; assert(1 <= ans[i][j] && ans[i][j] <= K); } } }
replace
38
39
38
53
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #include <numeric> using namespace std; #define rep(i, a, b) for (int64_t i = (a); i < (b); ++i) // a ≦ i < b #define Rrep(i, a, b) \ for (int64_t i = (a); i >= (b); --i) // reverse repeat. a から b まで減少. #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() // 逆イテレータ #define RANGE(a, b, c) \ (a).begin() + b, (a).begin() + c // コンテナ a の 要素 b から c へのイテレータ #define MOD 1000000007 #define INF 1000000000 typedef pair<int64_t, int64_t> PII; typedef vector<int64_t> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef vector<PII> VP; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, K; cin >> H >> W >> K; VS s(H); rep(i, 0, H) cin >> s[i]; string dotsline(W, '.'); VVI ans(H, VI(W, -1)); int n = 1; rep(i, 0, H) { if (s[i] != dotsline) { rep(j, 0, W) { if (s[i][j] == '#') { ans[i][j] = n; ++n; } else { ans[i][j] = n; } } if (s[i][W - 1] == '.') { --n; for (int j = W - 1; s[i][j] == '.'; --j) ans[i][j] = n; ++n; } } } rep(i, 0, H - 1) { if (s[i] == dotsline) { int k = i; while (k < H && ans[k][0] == -1) ++k; if (k > H) continue; rep(j, 0, W) cout << ans[k][j] << ' '; cout << "\n"; } else { rep(j, 0, W) cout << ans[i][j] << ' '; cout << "\n"; } } if (s[H - 1] == dotsline) { int k = H - 1; while (ans[k][0] == -1) --k; rep(i, k + 1, H) rep(j, 0, W) cout << ans[k][j] << ' '; } else rep(i, 0, W) cout << ans[H - 1][i] << ' '; } // 境界,出力文字列 チェック // 可読性優先.高速化次点. // まずは全探索,分割統治,次にDP // 制限を見る // 偶奇,逆から,ソート,出現回数,出現位置,DP, 余事象,包除 // データ構造. 問題の特徴量.単調性,二分探索 // 存在判定:構成方法,入力の特徴 // gcd, lcm ,素因数分解. // 例外を十分に含む一般化.想像力の限界 // 小さい系から例示 // 始めは過剰に例示・場合分けしてもいい.各場合を確実に対処. // 自明な例から処理,除外. // 小数のときは,精度の設定する.doubel 変数に数値を入力するときは 123. とする. // テストケース作成は数表あり
#include <bits/stdc++.h> #include <cmath> #include <numeric> using namespace std; #define rep(i, a, b) for (int64_t i = (a); i < (b); ++i) // a ≦ i < b #define Rrep(i, a, b) \ for (int64_t i = (a); i >= (b); --i) // reverse repeat. a から b まで減少. #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() // 逆イテレータ #define RANGE(a, b, c) \ (a).begin() + b, (a).begin() + c // コンテナ a の 要素 b から c へのイテレータ #define MOD 1000000007 #define INF 1000000000 typedef pair<int64_t, int64_t> PII; typedef vector<int64_t> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef vector<PII> VP; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, K; cin >> H >> W >> K; VS s(H); rep(i, 0, H) cin >> s[i]; string dotsline(W, '.'); VVI ans(H, VI(W, -1)); int n = 1; rep(i, 0, H) { if (s[i] != dotsline) { rep(j, 0, W) { if (s[i][j] == '#') { ans[i][j] = n; ++n; } else { ans[i][j] = n; } } if (s[i][W - 1] == '.') { --n; for (int j = W - 1; s[i][j] == '.'; --j) ans[i][j] = n; ++n; } } } rep(i, 0, H - 1) { if (s[i] == dotsline) { int k = i; while (k < H && ans[k][0] == -1) ++k; if (k >= H) continue; rep(j, 0, W) cout << ans[k][j] << ' '; cout << "\n"; } else { rep(j, 0, W) cout << ans[i][j] << ' '; cout << "\n"; } } if (s[H - 1] == dotsline) { int k = H - 1; while (ans[k][0] == -1) --k; rep(i, k + 1, H) rep(j, 0, W) cout << ans[k][j] << ' '; } else rep(i, 0, W) cout << ans[H - 1][i] << ' '; } // 境界,出力文字列 チェック // 可読性優先.高速化次点. // まずは全探索,分割統治,次にDP // 制限を見る // 偶奇,逆から,ソート,出現回数,出現位置,DP, 余事象,包除 // データ構造. 問題の特徴量.単調性,二分探索 // 存在判定:構成方法,入力の特徴 // gcd, lcm ,素因数分解. // 例外を十分に含む一般化.想像力の限界 // 小さい系から例示 // 始めは過剰に例示・場合分けしてもいい.各場合を確実に対処. // 自明な例から処理,除外. // 小数のときは,精度の設定する.doubel 変数に数値を入力するときは 123. とする. // テストケース作成は数表あり
replace
54
55
54
55
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (int i = 0; i < h; ++i) { cin >> s[i]; } vector<int> cnt(h); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') cnt[i]++; } } vector<vector<int>> ans(h); int idx = 1; bool one = false; for (int i = 0; i < h; ++i) { if (cnt[i] == 0) continue; for (int j = 0; j < w; ++j) { int k = j; while (k < w) { if (one && s[i][k] == '#') { break; } else if (!one && s[i][k] == '#') { ans[i].push_back(idx); one = true; } else { ans[i].push_back(idx); } ++k; } j = k - 1; one = false; ++idx; } } for (int i = 0; i < h; ++i) { int tmp = i; while (ans[tmp].empty() && tmp < h) { ++tmp; } if (tmp == h) { while (ans[tmp].empty() && tmp > 0) { --tmp; } } for (int j = 0; j < w; ++j) { cout << ans[tmp][j] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); for (int i = 0; i < h; ++i) { cin >> s[i]; } vector<int> cnt(h); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') cnt[i]++; } } vector<vector<int>> ans(h); int idx = 1; bool one = false; for (int i = 0; i < h; ++i) { if (cnt[i] == 0) continue; for (int j = 0; j < w; ++j) { int k = j; while (k < w) { if (one && s[i][k] == '#') { break; } else if (!one && s[i][k] == '#') { ans[i].push_back(idx); one = true; } else { ans[i].push_back(idx); } ++k; } j = k - 1; one = false; ++idx; } } for (int i = 0; i < h; ++i) { int tmp = i; while (ans[tmp].empty() && tmp < h) { ++tmp; } if (tmp == h) { --tmp; while (ans[tmp].empty() && tmp > 0) { --tmp; } } for (int j = 0; j < w; ++j) { cout << ans[tmp][j] << " "; } cout << endl; } }
insert
65
65
65
67
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++) #define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++) #define MOD 1000000007 #define int long long #define ALL(a) (a).begin(), (a).end() #define vi vector<int> #define vii vector<vi> #define pii pair<int, int> #define priq priority_queue<int> #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key))) #define tii tuple<int, int, int> #define Priq priority_queue<int, vi, greater<int>> #define pb push_back #define mp make_pair #define INF (1ll << 60) signed main() { int H, W, K; cin >> H >> W >> K; vector<string> S(H); rep(i, 0, H) cin >> S[i]; vii A(H, vi(W)); int memo = 1; vector<bool> F(H, 1); rep(i, 0, H) { int count = 0; rep(j, 0, W) { A[i][j] = memo; if (S[i][j] == '#') { memo++; F[i] = 0; } } rep(j, 1, W) { if (A[i][j] == memo && S[i][W - 1] == '.') A[i][j] = A[i][j - 1]; } } rep(_, 0, H) { rep(i, 0, H) { rep(j, 0, W) { if (F[i]) { if (i == 0 || (i > 0 && F[i - 1])) { A[i][j] = A[i + 1][j]; } else A[i][j] = A[i - 1][j]; } } } } rep(i, 0, H) { rep(j, 0, W) cout << A[i][j] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++) #define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++) #define MOD 1000000007 #define int long long #define ALL(a) (a).begin(), (a).end() #define vi vector<int> #define vii vector<vi> #define pii pair<int, int> #define priq priority_queue<int> #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key))) #define tii tuple<int, int, int> #define Priq priority_queue<int, vi, greater<int>> #define pb push_back #define mp make_pair #define INF (1ll << 60) signed main() { int H, W, K; cin >> H >> W >> K; vector<string> S(H); rep(i, 0, H) cin >> S[i]; vii A(H, vi(W)); int memo = 1; vector<bool> F(H, 1); rep(i, 0, H) { int count = 0; rep(j, 0, W) { A[i][j] = memo; if (S[i][j] == '#') { memo++; F[i] = 0; } } rep(j, 1, W) { if (A[i][j] == memo && S[i][W - 1] == '.') A[i][j] = A[i][j - 1]; } } rep(_, 0, H) { rep(i, 0, H) { if (F[i]) { if (i > 0 && !F[i - 1]) { rep(j, 0, W) A[i][j] = A[i - 1][j]; F[i] = 0; } else if (i < H - 1 && !F[i + 1]) { rep(j, 0, W) A[i][j] = A[i + 1][j]; F[i] = 0; } } } } rep(i, 0, H) { rep(j, 0, W) cout << A[i][j] << " "; cout << endl; } }
replace
42
48
42
49
0
p02855
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; vector<string> field; int main() { // 入力 int H, W, K; cin >> H >> W >> K; field.resize(H); for (int h = 0; h < H; ++h) cin >> field[h]; vector<int> cnt(H); int ans[H][K]; rep(i, H) { rep(j, W) { ans[i][j] = 0; } } rep(i, H) { rep(j, W) { if (field[i][j] == '#') cnt[i]++; } } // rep(i,H) cout<<cnt[i]<<endl; // countが0ではなければそれぞれのれつで分割 ll tmp = 1; rep(i, H) { bool ok = false; if (cnt[i] != 0) { rep(j, W) { if (ok and field[i][j] == '#') tmp++; ans[i][j] = tmp; if (ok == false and field[i][j] == '#') ok = true; } tmp++; } } // 0を埋めていく作業 rep(i, W) { int tmp2 = 0; rep(j, H) { if (ans[j][i] == 0) ans[j][i] = tmp2; if (ans[j][i] != 0) tmp2 = ans[j][i]; } } rep(i, W) { int tmp3 = ans[H - 1][i]; for (int j = H - 1; j >= 0; j--) { if (ans[j][i] == 0) ans[j][i] = tmp3; if (ans[j][i] != 0) tmp3 = ans[j][i]; } } // 出力 rep(i, H) { rep(j, W) { cout << ans[i][j] << " "; } cout << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; vector<string> field; int main() { // 入力 int H, W, K; cin >> H >> W >> K; field.resize(H); for (int h = 0; h < H; ++h) cin >> field[h]; vector<int> cnt(H); int ans[H][W]; rep(i, H) { rep(j, W) { ans[i][j] = 0; } } rep(i, H) { rep(j, W) { if (field[i][j] == '#') cnt[i]++; } } // rep(i,H) cout<<cnt[i]<<endl; // countが0ではなければそれぞれのれつで分割 ll tmp = 1; rep(i, H) { bool ok = false; if (cnt[i] != 0) { rep(j, W) { if (ok and field[i][j] == '#') tmp++; ans[i][j] = tmp; if (ok == false and field[i][j] == '#') ok = true; } tmp++; } } // 0を埋めていく作業 rep(i, W) { int tmp2 = 0; rep(j, H) { if (ans[j][i] == 0) ans[j][i] = tmp2; if (ans[j][i] != 0) tmp2 = ans[j][i]; } } rep(i, W) { int tmp3 = ans[H - 1][i]; for (int j = H - 1; j >= 0; j--) { if (ans[j][i] == 0) ans[j][i] = tmp3; if (ans[j][i] != 0) tmp3 = ans[j][i]; } } // 出力 rep(i, H) { rep(j, W) { cout << ans[i][j] << " "; } cout << endl; } }
replace
42
43
42
43
0
p02855
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; string tmp; vector<vector<int>> ans; for (int i = 0; i < H; i++) { ans.emplace_back(vector<int>(W, 0)); } int S = 1; vector<bool> is_exist(W, false); for (int i = 0; i < H; i++) { cin >> tmp; for (int j = 0; j < W; j++) { if (tmp[j] == '#') { ans[i][j] = S; S++; is_exist[j] = true; } } } int prev = 0; for (int i = 0; i < W; i++) { prev = 0; for (int j = 0; j < H; j++) { if (ans[j][i] == 0) { ans[j][i] = prev; } prev = ans[j][i]; } prev = 0; for (int j = H - 1; j >= 0; j--) { if (ans[j][i] == 0) { if (ans[j][i] != 0) { prev = ans[j][i]; continue; } ans[j][i] = prev; } prev = ans[j][i]; } } bool flag = true; while (flag) { flag = false; for (int i = 0; i < W; i++) { if (!is_exist[i]) { flag = true; prev = 0; for (int j = 0; j < H; j++) { if (ans[j][i] != 0) continue; if (i == 0 || i == W - 1) { ans[j][i] = (i == 0 ? ans[j][i + 1] : ans[j][i - 1]); } else { ans[j][i] = ans[j][i + 1]; } if (ans[j][i] != 0) is_exist[i] = true; } } } } for (auto v : ans) { for (int e : v) { cout << e << " "; } cout << endl; } return 0; }
#include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; string tmp; vector<vector<int>> ans; for (int i = 0; i < H; i++) { ans.emplace_back(vector<int>(W, 0)); } int S = 1; vector<bool> is_exist(W, false); for (int i = 0; i < H; i++) { cin >> tmp; for (int j = 0; j < W; j++) { if (tmp[j] == '#') { ans[i][j] = S; S++; is_exist[j] = true; } } } int prev = 0; for (int i = 0; i < W; i++) { prev = 0; for (int j = 0; j < H; j++) { if (ans[j][i] == 0) { ans[j][i] = prev; } prev = ans[j][i]; } prev = 0; for (int j = H - 1; j >= 0; j--) { if (ans[j][i] == 0) { if (ans[j][i] != 0) { prev = ans[j][i]; continue; } ans[j][i] = prev; } prev = ans[j][i]; } } bool flag = true; while (flag) { flag = false; for (int i = 0; i < W; i++) { if (!is_exist[i]) { flag = true; prev = 0; for (int j = 0; j < H; j++) { if (ans[j][i] != 0) continue; if (i == 0 || i == W - 1) { ans[j][i] = (i == 0 ? ans[j][i + 1] : ans[j][i - 1]); } else { if (ans[j][i - 1] * ans[j][i + 1] == 0) { ans[j][i] = (ans[j][i - 1] == 0 ? ans[j][i + 1] : ans[j][i - 1]); } else { ans[j][i] = ans[j][i + 1]; } } if (ans[j][i] != 0) is_exist[i] = true; } } } } for (auto v : ans) { for (int e : v) { cout << e << " "; } cout << endl; } return 0; }
replace
61
62
61
66
TLE
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using vll = vector<long long>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define leftunique(a) \ { \ SORT(a); \ (a).erase(unique((a).begin(), (a).end()), (a).end()); \ } // leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 // 6 になる #define debug(x) cout << #x << " = " << (x) << endl; bool IsInt(double a) { int b = a / 1; if (a == b) { return true; } else { return false; } } bool coY() { cout << "Yes" << endl; } bool coN() { cout << "No" << endl; } const int mod = 1e9 + 7; const ll INF = 1LL << 60; // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // グラフ用 const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; // ここから書き始める ll combination(ll n, ll i) { ll count = 0; ll multi = 1; ll div = 1; int limit = i; while (count < limit) { multi *= n; n--; multi /= count + 1; count++; } return multi / div; } int main() { cout << setprecision(10); ll h, w, k; cin >> h >> w >> k; vector<string> field(h); rep(i, h) { cin >> field[i]; } vector<vector<ll>> ans(h, vector<ll>(w)); // 入力ok.それぞれのfieldは、次の#が出てくる手前までの区画でやればいい // イチゴがない場所を覚えておく vector<bool> ichigo(h, false); ll firstLine = -1; rep(i, h) { rep(j, w) { if (field[i][j] == '#') { if (firstLine == -1) { firstLine = i; // イチゴが最初に出てきたのは何行目か。 } else { ichigo[i] = true; break; } } } } ll count = 0; for (int i = firstLine; i < h; i++) { // イチゴが出てきたラインから作 bool onetime = false; // 行ごとに2回目出てくるまでは前の行+1 // 行が変わったとき、その行にイチゴがあるんだったら+1 if (ichigo[i]) count++; rep(j, w) { if (ichigo[i] == false) { // イチゴがないんだったら、上のものをそのまま使う ans[i][j] = ans[i - 1][j]; } else { if (field[i][j] == '#' && onetime) { count++; ans[i][j] = count; } else if (field[i][j] == '#') { ans[i][j] = count; onetime = true; } else { ans[i][j] = count; } } } // 行が変わるごとに、その行にイチゴがあるんだったらカウントを++する } // firstline より前を構築していく for (int i = firstLine - 1; i >= 0; i--) { rep(j, w) { ans[i][j] = ans[i + 1][j]; } } rep(i, h) { rep(j, w) { cout << ans[i][j] << " "; } cout << endl; } // 一行目日以後がなければ、全部j }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using vll = vector<long long>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define leftunique(a) \ { \ SORT(a); \ (a).erase(unique((a).begin(), (a).end()), (a).end()); \ } // leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 // 6 になる #define debug(x) cout << #x << " = " << (x) << endl; bool IsInt(double a) { int b = a / 1; if (a == b) { return true; } else { return false; } } bool coY() { cout << "Yes" << endl; } bool coN() { cout << "No" << endl; } const int mod = 1e9 + 7; const ll INF = 1LL << 60; // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // グラフ用 const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; // ここから書き始める ll combination(ll n, ll i) { ll count = 0; ll multi = 1; ll div = 1; int limit = i; while (count < limit) { multi *= n; n--; multi /= count + 1; count++; } return multi / div; } int main() { cout << setprecision(10); ll h, w, k; cin >> h >> w >> k; vector<string> field(h); rep(i, h) { cin >> field[i]; } vector<vector<ll>> ans(h, vector<ll>(w)); // 入力ok.それぞれのfieldは、次の#が出てくる手前までの区画でやればいい // イチゴがない場所を覚えておく vector<bool> ichigo(h, false); ll firstLine = -1; rep(i, h) { rep(j, w) { if (field[i][j] == '#') { if (firstLine == -1) { firstLine = i; // イチゴが最初に出てきたのは何行目か。 ichigo[i] = true; } else { ichigo[i] = true; break; } } } } ll count = 0; for (int i = firstLine; i < h; i++) { // イチゴが出てきたラインから作 bool onetime = false; // 行ごとに2回目出てくるまでは前の行+1 // 行が変わったとき、その行にイチゴがあるんだったら+1 if (ichigo[i]) count++; rep(j, w) { if (ichigo[i] == false) { // イチゴがないんだったら、上のものをそのまま使う ans[i][j] = ans[i - 1][j]; } else { if (field[i][j] == '#' && onetime) { count++; ans[i][j] = count; } else if (field[i][j] == '#') { ans[i][j] = count; onetime = true; } else { ans[i][j] = count; } } } // 行が変わるごとに、その行にイチゴがあるんだったらカウントを++する } // firstline より前を構築していく for (int i = firstLine - 1; i >= 0; i--) { rep(j, w) { ans[i][j] = ans[i + 1][j]; } } rep(i, h) { rep(j, w) { cout << ans[i][j] << " "; } cout << endl; } // 一行目日以後がなければ、全部j }
insert
94
94
94
95
0
p02855
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <new> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <unordered_map> #include <vector> typedef long long ll; typedef unsigned long long ull; constexpr ll mop = 1000000007; constexpr ll mop2 = 998244353; using namespace std; int main() { ll h, w, k; cin >> h >> w >> k; vector<vector<bool>> grid(h); vector<bool> existSt(h); vector<vector<ll>> ans(h); ll minrow = INT64_MAX; for (ll i = 0; i < h; i++) { grid[i].resize(w); ans[i].resize(w); string str; cin >> str; for (ll j = 0; j < w; j++) { if (str[j] == '#') { grid[i][j] = true; if (minrow > j) { minrow = j; } existSt[i] = true; } } } ll nowNo = 1; for (ll i = minrow; i < h; i++) { if (existSt[i] == false) { for (ll j = 0; j < w; j++) { ans[i][j] = ans[i - 1][j]; } } else { bool discoverOne = false; for (ll j = 0; j < w; j++) { if (grid[i][j] == true) { if (discoverOne) { nowNo++; } else { discoverOne = true; } } ans[i][j] = nowNo; } nowNo++; } } for (ll i = 0; i < minrow; i++) { for (ll j = 0; j < w; j++) { if (j != 0) { cout << " "; } cout << ans[minrow][j]; } cout << endl; } for (ll i = minrow; i < h; i++) { for (ll j = 0; j < w; j++) { if (j != 0) { cout << " "; } cout << ans[i][j]; } cout << endl; } }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <new> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <unordered_map> #include <vector> typedef long long ll; typedef unsigned long long ull; constexpr ll mop = 1000000007; constexpr ll mop2 = 998244353; using namespace std; int main() { ll h, w, k; cin >> h >> w >> k; vector<vector<bool>> grid(h); vector<bool> existSt(h); vector<vector<ll>> ans(h); ll minrow = INT64_MAX; for (ll i = 0; i < h; i++) { grid[i].resize(w); ans[i].resize(w); string str; cin >> str; for (ll j = 0; j < w; j++) { if (str[j] == '#') { grid[i][j] = true; if (minrow > i) { minrow = i; } existSt[i] = true; } } } ll nowNo = 1; for (ll i = minrow; i < h; i++) { if (existSt[i] == false) { for (ll j = 0; j < w; j++) { ans[i][j] = ans[i - 1][j]; } } else { bool discoverOne = false; for (ll j = 0; j < w; j++) { if (grid[i][j] == true) { if (discoverOne) { nowNo++; } else { discoverOne = true; } } ans[i][j] = nowNo; } nowNo++; } } for (ll i = 0; i < minrow; i++) { for (ll j = 0; j < w; j++) { if (j != 0) { cout << " "; } cout << ans[minrow][j]; } cout << endl; } for (ll i = minrow; i < h; i++) { for (ll j = 0; j < w; j++) { if (j != 0) { cout << " "; } cout << ans[i][j]; } cout << endl; } }
replace
47
49
47
49
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep0(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() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using Graph = vector<vi>; // vi <=> vl using vb = vector<bool>; using boolGraph = vector<vb>; using P = pair<int, int>; // int <=> ll const int MOD = 1e9 + 7; const int MOD2 = 998244353; const double EPS = 1e-9; template <typename T> struct is_vector : false_type {}; template <typename T> struct is_vector<vector<T>> : true_type {}; template <typename T> ostream &operator<<(ostream &ostr, const vector<T> &vec) { if (vec.empty()) { return ostr; } ostr << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) { if (is_vector<T>()) ostr << "\n" << *itr; else ostr << ' ' << *itr; } return ostr; } void solve() { int h, w, k; cin >> h >> w >> k; vector<string> G(h); rep(i, h) cin >> G[i]; Graph ans(h, vi(w)); int idx = 1; vi vec_h; rep(i, h) { int prev = 0; rep(j, w) { if (G[i][j] == '#') { while (prev <= j) { ans[i][prev] = idx; for (auto p : vec_h) { ans[p][prev] = idx; } ++prev; } ++idx; } } if (prev == 0) { vec_h.push_back(h); continue; } while (prev < w) { ans[i][prev] = ans[i][prev - 1]; for (auto p : vec_h) { ans[p][prev] = ans[p][prev - 1]; } ++prev; } vec_h.clear(); } rep(j, w) { for (auto p : vec_h) { ans[p][j] = ans[p - 1][j]; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep0(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() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using Graph = vector<vi>; // vi <=> vl using vb = vector<bool>; using boolGraph = vector<vb>; using P = pair<int, int>; // int <=> ll const int MOD = 1e9 + 7; const int MOD2 = 998244353; const double EPS = 1e-9; template <typename T> struct is_vector : false_type {}; template <typename T> struct is_vector<vector<T>> : true_type {}; template <typename T> ostream &operator<<(ostream &ostr, const vector<T> &vec) { if (vec.empty()) { return ostr; } ostr << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) { if (is_vector<T>()) ostr << "\n" << *itr; else ostr << ' ' << *itr; } return ostr; } void solve() { int h, w, k; cin >> h >> w >> k; vector<string> G(h); rep(i, h) cin >> G[i]; Graph ans(h, vi(w)); int idx = 1; vi vec_h; rep(i, h) { int prev = 0; rep(j, w) { if (G[i][j] == '#') { while (prev <= j) { ans[i][prev] = idx; for (auto p : vec_h) { ans[p][prev] = idx; } ++prev; } ++idx; } } if (prev == 0) { vec_h.push_back(i); continue; } while (prev < w) { ans[i][prev] = ans[i][prev - 1]; for (auto p : vec_h) { ans[p][prev] = ans[p][prev - 1]; } ++prev; } vec_h.clear(); } rep(j, w) { for (auto p : vec_h) { ans[p][j] = ans[p - 1][j]; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); solve(); return 0; }
replace
60
61
60
61
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define sz(x) ll(x.size()) using namespace std; int main() { ll h, w, k, kind = 1; char s; cin >> h >> w >> k; vector<vector<ll>> a(h, vector<ll>(w)); rep(i, h) rep(j, w) { cin >> s; if (s == '#') { a.at(i).at(j) = kind; kind++; } } rep(i, h) { ll ind = 0; rep(j, w) { if (a.at(i).at(j) != 0) { for (ll k = ind; k < j; k++) a.at(i).at(k) = a.at(i).at(j); ind = j + 1; } else if (j == w - 1) { for (ll k = max((ll)0, ind - 1); k < w; k++) a.at(i).at(k) = a.at(i).at(max((ll)0, ind - 1)); } } } rep(i, h) { rep(j, w) { if (a.at(i).at(j) == 0 && i != 0) a.at(i).at(j) = a.at(i - 1).at(j); } } rep(i, h) { rep(j, w) { if (a.at(h - 1 - i).at(j) == 0 && h - 1 - i != h - 1) a.at(h - 1 - i).at(j) = a.at(h - 2 - i).at(j); } } rep(i, h) { rep(j, w) cout << a.at(i).at(j) << " "; cout << endl; } }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define sz(x) ll(x.size()) using namespace std; int main() { ll h, w, k, kind = 1; char s; cin >> h >> w >> k; vector<vector<ll>> a(h, vector<ll>(w)); rep(i, h) rep(j, w) { cin >> s; if (s == '#') { a.at(i).at(j) = kind; kind++; } } rep(i, h) { ll ind = 0; rep(j, w) { if (a.at(i).at(j) != 0) { for (ll k = ind; k < j; k++) a.at(i).at(k) = a.at(i).at(j); ind = j + 1; } else if (j == w - 1) { for (ll k = max((ll)0, ind - 1); k < w; k++) a.at(i).at(k) = a.at(i).at(max((ll)0, ind - 1)); } } } rep(i, h) { rep(j, w) { if (a.at(i).at(j) == 0 && i != 0) a.at(i).at(j) = a.at(i - 1).at(j); } } rep(i, h) { rep(j, w) { if (a.at(h - 1 - i).at(j) == 0 && h - 1 - i != h - 1) a.at(h - 1 - i).at(j) = a.at(h - i).at(j); } } rep(i, h) { rep(j, w) cout << a.at(i).at(j) << " "; cout << endl; } }
replace
40
41
40
41
0
p02855
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; vector<vector<int>> ichigo; int main() { int H, W, K; cin >> H >> W >> K; ichigo.resize(H); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char c; cin >> c; if (c == '#') ichigo[i].push_back(j); } } int nothing = -1; int ans[300][300] = {}; int cnt = 1; for (int i = 0; i < H; i++) { if (ichigo[i].size() == 0 && nothing == -1) { nothing = i; } else { int s; if (nothing == -1) s = i; else s = nothing; nothing = -1; if (ichigo[i].size() == 1) { for (int w = 0; w < W; w++) { for (int h = s; h <= i; h++) ans[h][w] = cnt; } } else { for (int w = 0; w <= ichigo[i][0]; w++) for (int h = s; h <= i; h++) ans[h][w] = cnt; int idx = 1; for (int w = ichigo[i][0] + 1; w < W; w++) { for (int h = s; h <= i; h++) ans[h][w] = cnt; if (idx < ichigo[i].size() && ichigo[i][idx] == w) { cnt++; idx++; for (int h = s; h <= i; h++) ans[h][w] = cnt; } } } cnt++; } } if (nothing != -1) { cnt -= ichigo[nothing - 1].size(); int s = nothing; if (ichigo[nothing - 1].size() == 1) { for (int w = 0; w < W; w++) { for (int h = s; h < H; h++) ans[h][w] = cnt; } } else { for (int w = 0; w <= ichigo[nothing - 1][0]; w++) for (int h = s; h < H; h++) ans[h][w] = cnt; int idx = 1; for (int w = ichigo[nothing - 1][0] + 1; w < W; w++) { for (int h = s; h < H; h++) ans[h][w] = cnt; if (idx < ichigo[nothing - 1].size() && ichigo[nothing - 1][idx] == w) { cnt++; idx++; for (int h = s; h < H; h++) ans[h][w] = cnt; } } } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cout << ans[i][j] << " "; cout << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; vector<vector<int>> ichigo; int main() { int H, W, K; cin >> H >> W >> K; ichigo.resize(H); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char c; cin >> c; if (c == '#') ichigo[i].push_back(j); } } int nothing = -1; int ans[300][300] = {}; int cnt = 1; for (int i = 0; i < H; i++) { if (ichigo[i].size() == 0 && nothing == -1) { nothing = i; } else if (ichigo[i].size() != 0) { int s; if (nothing == -1) s = i; else s = nothing; nothing = -1; if (ichigo[i].size() == 1) { for (int w = 0; w < W; w++) { for (int h = s; h <= i; h++) ans[h][w] = cnt; } } else { for (int w = 0; w <= ichigo[i][0]; w++) for (int h = s; h <= i; h++) ans[h][w] = cnt; int idx = 1; for (int w = ichigo[i][0] + 1; w < W; w++) { for (int h = s; h <= i; h++) ans[h][w] = cnt; if (idx < ichigo[i].size() && ichigo[i][idx] == w) { cnt++; idx++; for (int h = s; h <= i; h++) ans[h][w] = cnt; } } } cnt++; } } if (nothing != -1) { cnt -= ichigo[nothing - 1].size(); int s = nothing; if (ichigo[nothing - 1].size() == 1) { for (int w = 0; w < W; w++) { for (int h = s; h < H; h++) ans[h][w] = cnt; } } else { for (int w = 0; w <= ichigo[nothing - 1][0]; w++) for (int h = s; h < H; h++) ans[h][w] = cnt; int idx = 1; for (int w = ichigo[nothing - 1][0] + 1; w < W; w++) { for (int h = s; h < H; h++) ans[h][w] = cnt; if (idx < ichigo[nothing - 1].size() && ichigo[nothing - 1][idx] == w) { cnt++; idx++; for (int h = s; h < H; h++) ans[h][w] = cnt; } } } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cout << ans[i][j] << " "; cout << endl; } return 0; }
replace
29
30
29
30
0
p02855
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; int sup = h; vector<vector<int>> cnt(h); string *s = new string[h]; int **ans = new int *[h]; for (int i = 0; i < h; i++) { ans[i] = new int[w]; cin >> s[i]; int sz = 0; for (int j = 0; j < w; j++) { if (s[i][j] == '#') { cnt[i].push_back(j); sz++; } } if (sz == 0 && sup == h) sup = i; } int l = 1; for (int i = 0; i < h; i++) { if (cnt[i].size() == 0) continue; else { int m = 0; int sz = cnt[i].size(); while (sz > 1) { bool can = false; while (s[i][m] != '#' || !can) { if (s[i][m] == '#') can = true; ans[i][m] = l; m++; } l++; sz--; } for (int a = m; a < w; a++) ans[i][a] = l; l++; } } for (int i = 0; i < h; i++) { if (cnt[i].size() == 0 && i == 0) { int m = i + 1; while (!cnt[m].size()) m++; for (int j = 0; j < w; j++) { ans[i][j] = ans[m][j]; } } else if (cnt[i].size() == 0) { int m = i - 1; while (!cnt[m].size()) m--; for (int j = 0; j < w; j++) { ans[i][j] = ans[m][j]; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cout << ans[i][j] << " "; } cout << endl; } }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; int sup = h; vector<vector<int>> cnt(h); string *s = new string[h]; int **ans = new int *[h]; for (int i = 0; i < h; i++) { ans[i] = new int[w]; cin >> s[i]; int sz = 0; for (int j = 0; j < w; j++) { if (s[i][j] == '#') { cnt[i].push_back(j); sz++; } } if (sz == 0 && sup == h) sup = i; } int l = 1; for (int i = 0; i < h; i++) { if (cnt[i].size() == 0) continue; else { int m = 0; int sz = cnt[i].size(); while (sz > 1) { bool can = false; while (s[i][m] != '#' || !can) { if (s[i][m] == '#') can = true; ans[i][m] = l; m++; } l++; sz--; } for (int a = m; a < w; a++) ans[i][a] = l; l++; } } for (int i = 0; i < h; i++) { if (cnt[i].size() == 0 && i == 0) { int m = i + 1; while (!cnt[m].size()) m++; for (int j = 0; j < w; j++) { ans[i][j] = ans[m][j]; } } else if (cnt[i].size() == 0) { int m = i - 1; while (!ans[m][0]) m--; for (int j = 0; j < w; j++) { ans[i][j] = ans[m][j]; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cout << ans[i][j] << " "; } cout << endl; } }
replace
64
65
64
65
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> #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 FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RVSORT(v) sort(v.rbegin(), v.rend()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } ll modpow(ll n, ll k) { if (k == 1) { return n; } else if (k == 0) { return 1; } else if (k % 2 == 0) { ll memo = modpow(n, k / 2) % MOD; return memo * memo % MOD; } else { return n * modpow(n, k - 1) % MOD; } } int main() { int h, w, k; cin >> h >> w >> k; string s[w]; int cake[h][w]; REP(i, h) { REP(j, w) { cake[i][j] = -1; } } int count = 1; REP(i, h) { cin >> s[i]; REP(j, w) { if (s[i][j] == '#') { cake[i][j] = count; count++; } } } REP(i, h) { REP(j, w) { if (cake[i][j] != -1) { int p, q; int now = cake[i][j]; p = i; q = j - 1; while (q >= 0 && cake[p][q] == -1) { cake[p][q] = now; q--; } q = j + 1; while (q < w && cake[p][q] == -1) { cake[p][q] = now; q++; } } } } REP(i, h) { REP(j, w) { if (cake[i][j] != -1) { int p, q; int now = cake[i][j]; p = i - 1; q = j; while (p >= 0 && cake[p][q] == -1) { cake[p][q] = now; p--; } p = i + 1; while (p < h && cake[p][q] == -1) { cake[p][q] = now; p++; } } } } REP(i, h) { REP(j, w) { cout << cake[i][j] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> #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 FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RVSORT(v) sort(v.rbegin(), v.rend()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } ll modpow(ll n, ll k) { if (k == 1) { return n; } else if (k == 0) { return 1; } else if (k % 2 == 0) { ll memo = modpow(n, k / 2) % MOD; return memo * memo % MOD; } else { return n * modpow(n, k - 1) % MOD; } } int main() { int h, w, k; cin >> h >> w >> k; string s[h]; int cake[h][w]; REP(i, h) { REP(j, w) { cake[i][j] = -1; } } int count = 1; REP(i, h) { cin >> s[i]; REP(j, w) { if (s[i][j] == '#') { cake[i][j] = count; count++; } } } REP(i, h) { REP(j, w) { if (cake[i][j] != -1) { int p, q; int now = cake[i][j]; p = i; q = j - 1; while (q >= 0 && cake[p][q] == -1) { cake[p][q] = now; q--; } q = j + 1; while (q < w && cake[p][q] == -1) { cake[p][q] = now; q++; } } } } REP(i, h) { REP(j, w) { if (cake[i][j] != -1) { int p, q; int now = cake[i][j]; p = i - 1; q = j; while (p >= 0 && cake[p][q] == -1) { cake[p][q] = now; p--; } p = i + 1; while (p < h && cake[p][q] == -1) { cake[p][q] = now; p++; } } } } REP(i, h) { REP(j, w) { cout << cake[i][j] << " "; } cout << endl; } return 0; }
replace
40
41
40
41
0
p02855
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <random> #include <string> #include <vector> // 使い方がよくわからない #include <bitset> #include <queue> #include <sstream> #include <stack> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define co(x) cout << x << endl #define cosp(x) cout << x << " " using namespace std; using ll = long long; int main(int argc, const char *argv[]) { ll h, w, k; cin >> h >> w >> k; vector<string> s(h); rep(i, h) cin >> s[i]; vector<vector<int>> vec(h, vector<int>(w, 0)); ll fi = 0; ll ki = 0; rep(i, h) { vector<int> pl; pl.push_back(-1); rep(j, w) { if (s[i][j] == '#') { pl.push_back(j); } } pl[pl.size() - 1] = w; rep(l, pl.size() - 1) { ki++; for (int wi = pl[l] + 1; wi <= pl[l + 1]; wi++) { for (int hi = fi; hi <= i; hi++) { vec[hi][wi] = ki; } } } if (pl.size() > 1) fi = i + 1; } if (fi > 0) { for (int i = fi; i < h; i++) { rep(j, w) { vec[i][j] = vec[fi - 1][j]; } } } rep(i, h) { rep(j, w - 1) { cosp(vec[i][j]); } co(vec[i][w - 1]); } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <random> #include <string> #include <vector> // 使い方がよくわからない #include <bitset> #include <queue> #include <sstream> #include <stack> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define co(x) cout << x << endl #define cosp(x) cout << x << " " using namespace std; using ll = long long; int main(int argc, const char *argv[]) { ll h, w, k; cin >> h >> w >> k; vector<string> s(h); rep(i, h) cin >> s[i]; vector<vector<int>> vec(h, vector<int>(w, 0)); ll fi = 0; ll ki = 0; rep(i, h) { vector<int> pl; pl.push_back(-1); rep(j, w) { if (s[i][j] == '#') { pl.push_back(j); } } pl[pl.size() - 1] = w - 1; rep(l, pl.size() - 1) { ki++; for (int wi = pl[l] + 1; wi <= pl[l + 1]; wi++) { for (int hi = fi; hi <= i; hi++) { vec[hi][wi] = ki; } } } if (pl.size() > 1) fi = i + 1; } if (fi > 0) { for (int i = fi; i < h; i++) { rep(j, w) { vec[i][j] = vec[fi - 1][j]; } } } rep(i, h) { rep(j, w - 1) { cosp(vec[i][j]); } co(vec[i][w - 1]); } return 0; }
replace
38
39
38
39
0
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) int main() { ll H, W, K; cin >> H >> W >> K; vector<string> s(H); vector<vector<ll>> ans(H, vector<ll>(W, 0)); vector<bool> hit(H, false); REP(i, H) { cin >> s[i]; REP(j, W) { if (s[i][j] == '#') { hit[i] = true; } } } ll cnt = 1; REP(i, H) if (hit[i]) { REP(j, W) { ans[i][j] = cnt; if (s[i][j] == '#') { cnt++; } } if (s[i][W - 1] == '#') { continue; } ll p = W - 1; while (s[i][p] == '.') { ans[i][p] = cnt - 1; p--; } } REP(i, H) if (!hit[i]) { ll p = i; while (p < H && !hit[p]) { p++; } // 上からコピー if (p == W) { p = i; while (p > 0 && !hit[p]) { p--; } } REP(j, W) { ans[i][j] = ans[p][j]; } hit[i] = true; } REP(i, H) { REP(j, W) { cout << ans[i][j] << " \n"[j == W - 1]; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) int main() { ll H, W, K; cin >> H >> W >> K; vector<string> s(H); vector<vector<ll>> ans(H, vector<ll>(W, 0)); vector<bool> hit(H, false); REP(i, H) { cin >> s[i]; REP(j, W) { if (s[i][j] == '#') { hit[i] = true; } } } ll cnt = 1; REP(i, H) if (hit[i]) { REP(j, W) { ans[i][j] = cnt; if (s[i][j] == '#') { cnt++; } } if (s[i][W - 1] == '#') { continue; } ll p = W - 1; while (s[i][p] == '.') { ans[i][p] = cnt - 1; p--; } } REP(i, H) if (!hit[i]) { ll p = i; while (p < H && !hit[p]) { p++; } // 上からコピー if (p == H) { p = i; while (p > 0 && !hit[p]) { p--; } } REP(j, W) { ans[i][j] = ans[p][j]; } hit[i] = true; } REP(i, H) { REP(j, W) { cout << ans[i][j] << " \n"[j == W - 1]; } } }
replace
53
54
53
54
0
p02855
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define all(x) (x).begin(), (x).end() #define MOD 1000000007 #define INF (1LL << 62) #define PI (acos(-1)) #define print(x) cout << x << endl 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; } typedef pair<ll, ll> P; static const ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i]; if (i != (int)v.size() - 1) os << " "; } return os; } int main() { ll H, W, K; cin >> H >> W >> K; vector<vector<ll>> s(H, vector<ll>(W)); vector<vector<ll>> a(H, vector<ll>(W, 0)); rep(i, H) { string t; cin >> t; rep(j, W) { s[i][j] = t[j] == '#'; } } bool exist = false; ll num = 1; rep(i, H) { exist = false; ll pre = 0; rep(j, W) { if (s[i][j]) { exist = true; for (ll k = pre; k <= j; k++) { a[i][k] = num; } pre = j + 1; num++; } else if (exist && j == W - 1) { for (ll k = pre; k <= j; k++) { a[i][k] = num - 1; } } } } bool flag = true; while (flag) { flag = false; rep(i, H) { if (a[i][0] == 0) { flag = true; if (i == 0) { rep(j, W) { a[i][j] = a[i + 1][j]; } } else { rep(j, W) { a[i][j] = a[i - 1][j]; } } } } } rep(i, H) print(a[i]); return 0; }
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define all(x) (x).begin(), (x).end() #define MOD 1000000007 #define INF (1LL << 62) #define PI (acos(-1)) #define print(x) cout << x << endl 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; } typedef pair<ll, ll> P; static const ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i]; if (i != (int)v.size() - 1) os << " "; } return os; } int main() { ll H, W, K; cin >> H >> W >> K; vector<vector<ll>> s(H, vector<ll>(W)); vector<vector<ll>> a(H, vector<ll>(W, 0)); rep(i, H) { string t; cin >> t; rep(j, W) { s[i][j] = t[j] == '#'; } } bool exist = false; ll num = 1; rep(i, H) { exist = false; ll pre = 0; rep(j, W) { if (s[i][j]) { exist = true; for (ll k = pre; k <= j; k++) { a[i][k] = num; } pre = j + 1; num++; } else if (exist && j == W - 1) { for (ll k = pre; k <= j; k++) { a[i][k] = num - 1; } } } } rep(i, H) { if (i == 0) continue; if (a[i][0] == 0) { rep(j, W) { a[i][j] = a[i - 1][j]; } } } repr(i, H) { if (i == H - 1) continue; if (a[i][0] == 0) { rep(j, W) { a[i][j] = a[i + 1][j]; } } } rep(i, H) print(a[i]); return 0; }
replace
59
71
59
72
TLE
p02855
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)x.size()) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef vector<int> vi; typedef vector<vi> vvi; /*{ }*/ int h, w, k; string S[300]; int ans[301][301]; int s[301][301]; signed main() { cin >> h >> w >> k; rep(i, 0, h) cin >> S[i]; rep(i, 0, h) rep(j, 0, w) { if (S[i][j] == '#') { s[i + 1][j + 1] = 1; } } rep(i, 0, h + 1) rep(j, 0, w) s[i][j + 1] += s[i][j]; rep(i, 0, w + 1) rep(j, 0, h) s[j + 1][i] += s[j][i]; int num = 1, cnt = 0; rep(i, 0, h) { int c = 0, next = 0; rep(j, 0, w) { if (S[i][j] == '#') c++; if (c == 2) { rep(u, i - cnt, i + 1) rep(k, next, j) ans[u][k] = num; c--; num++; next = j; } } if (c == 0) cnt++; else { rep(u, i - cnt, i + 1) rep(j, next, w) ans[u][j] = num; num++; cnt = 0; } } for (int i = 1; i < h; i--) { rep(j, 0, w) if (ans[i][j] == 0) ans[i][j] = ans[i - 1][j]; } rep(i, 0, h) rep(j, 0, w) cout << ans[i][j] << " \n"[j == w - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)x.size()) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef vector<int> vi; typedef vector<vi> vvi; /*{ }*/ int h, w, k; string S[300]; int ans[301][301]; int s[301][301]; signed main() { cin >> h >> w >> k; rep(i, 0, h) cin >> S[i]; rep(i, 0, h) rep(j, 0, w) { if (S[i][j] == '#') { s[i + 1][j + 1] = 1; } } rep(i, 0, h + 1) rep(j, 0, w) s[i][j + 1] += s[i][j]; rep(i, 0, w + 1) rep(j, 0, h) s[j + 1][i] += s[j][i]; int num = 1, cnt = 0; rep(i, 0, h) { int c = 0, next = 0; rep(j, 0, w) { if (S[i][j] == '#') c++; if (c == 2) { rep(u, i - cnt, i + 1) rep(k, next, j) ans[u][k] = num; c--; num++; next = j; } } if (c == 0) cnt++; else { rep(u, i - cnt, i + 1) rep(j, next, w) ans[u][j] = num; num++; cnt = 0; } } rep(i, 1, h) { rep(j, 0, w) if (ans[i][j] == 0) ans[i][j] = ans[i - 1][j]; } rep(i, 0, h) rep(j, 0, w) cout << ans[i][j] << " \n"[j == w - 1]; return 0; }
replace
69
72
69
70
-11
p02856
C++
Runtime Error
#include <bits/stdc++.h> #define LARB 1 #define RARB 30000 #define inf 1e18 #define zeros(x) ((x ^ (x - 1)) & x) #define endl '\n' #define eps 1e-9 #define mod 1000000007 #define NMAX 300 using namespace std; typedef long long ll; typedef long double ld; ll d, c, tot, sum, n; vector<pair<ll, ll>> Init; ll norm(ll &sum) { ll nr = 0, steps = 0; while (sum) { nr += sum % 10; steps++; sum /= 10; } ll ans = steps - 1; if (nr >= 10) ans += norm(nr); sum = nr; return ans; } ll compute(pair<ll, ll> pr, ll &sum); ll group(pair<ll, ll> pr, ll &sum, ll grsize, ll nxt) { if (pr.second % grsize == 0) return (grsize - 1) * (pr.second / grsize) + pr.second / grsize + compute({nxt, pr.second / grsize}, sum); else { ll def = 0; if (sum == 0) { def = pr.second % grsize - 1; } else { def = pr.second % grsize; } sum += (pr.second % grsize) * pr.first; if (sum > 9) def += norm(sum); return (grsize - 1) * (pr.second / grsize) + pr.second / grsize + def + compute({nxt, pr.second / grsize}, sum); } } ll compute(pair<ll, ll> pr, ll &sum) { if (pr.second == 0) return 0; ll base = pr.second - (sum == 0); if (pr.first == 0) return base; if (pr.first == 1) return group(pr, sum, 10, 1); if (pr.first == 2) return group(pr, sum, 5, 1); if (pr.first == 3) return group(pr, sum, 4, 3); if (pr.first == 4) return group(pr, sum, 3, 3); if (pr.first == 5) return group(pr, sum, 2, 1); if (pr.first == 6) return group(pr, sum, 2, 3); if (pr.first == 7) return group(pr, sum, 2, 5); if (pr.first == 8) return group(pr, sum, 2, 7); if (pr.first == 9) return group(pr, sum, 2, 9); assert(false); } int main() { freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; i++) { cin >> d >> c; Init.push_back({d, c}); } ll sum = 0; for (auto i : Init) { tot += compute(i, sum); } cout << tot; return 0; }
#include <bits/stdc++.h> #define LARB 1 #define RARB 30000 #define inf 1e18 #define zeros(x) ((x ^ (x - 1)) & x) #define endl '\n' #define eps 1e-9 #define mod 1000000007 #define NMAX 300 using namespace std; typedef long long ll; typedef long double ld; ll d, c, tot, sum, n; vector<pair<ll, ll>> Init; ll norm(ll &sum) { ll nr = 0, steps = 0; while (sum) { nr += sum % 10; steps++; sum /= 10; } ll ans = steps - 1; if (nr >= 10) ans += norm(nr); sum = nr; return ans; } ll compute(pair<ll, ll> pr, ll &sum); ll group(pair<ll, ll> pr, ll &sum, ll grsize, ll nxt) { if (pr.second % grsize == 0) return (grsize - 1) * (pr.second / grsize) + pr.second / grsize + compute({nxt, pr.second / grsize}, sum); else { ll def = 0; if (sum == 0) { def = pr.second % grsize - 1; } else { def = pr.second % grsize; } sum += (pr.second % grsize) * pr.first; if (sum > 9) def += norm(sum); return (grsize - 1) * (pr.second / grsize) + pr.second / grsize + def + compute({nxt, pr.second / grsize}, sum); } } ll compute(pair<ll, ll> pr, ll &sum) { if (pr.second == 0) return 0; ll base = pr.second - (sum == 0); if (pr.first == 0) return base; if (pr.first == 1) return group(pr, sum, 10, 1); if (pr.first == 2) return group(pr, sum, 5, 1); if (pr.first == 3) return group(pr, sum, 4, 3); if (pr.first == 4) return group(pr, sum, 3, 3); if (pr.first == 5) return group(pr, sum, 2, 1); if (pr.first == 6) return group(pr, sum, 2, 3); if (pr.first == 7) return group(pr, sum, 2, 5); if (pr.first == 8) return group(pr, sum, 2, 7); if (pr.first == 9) return group(pr, sum, 2, 9); assert(false); } int main() { // freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; i++) { cin >> d >> c; Init.push_back({d, c}); } ll sum = 0; for (auto i : Init) { tot += compute(i, sum); } cout << tot; return 0; }
replace
94
95
94
95
0
p02856
C++
Runtime Error
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rfor(i, m, n) for (int i = (m); i >= (n); --i) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r) using namespace std; using ll = long long; using ld = long double; using VB = vector<bool>; using VVB = vector<VB>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using VS = vector<string>; using VD = vector<ld>; using PII = pair<int, int>; using VP = vector<PII>; using PLL = pair<ll, ll>; using VPL = vector<PLL>; template <class T> using PQ = priority_queue<T>; template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = (int)1e9; constexpr ll inf_ll = (ll)1e18, MOD = 1000000007; constexpr ld PI = M_PI, EPS = 1e-12; // --- input --- // #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #define putchar_unlocked _putchar_nolock #define fwrite_unlocked fwrite #define fflush_unlocked _fflush_nolock #endif inline int gc() { return getchar_unlocked(); } template <class T> inline void InputF(T &v) { cin >> v; } inline void InputF(char &v) { while (isspace(v = gc())) ; } inline void InputF(bool &v) { char c; InputF(c); v = c != '0'; } inline void InputF(string &v) { v.clear(); char c; for (InputF(c); !isspace(c); c = gc()) v += c; } inline void InputF(int &v) { bool neg = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (neg) v = -v; } inline void InputF(long long &v) { bool neg = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (neg) v = -v; } inline void InputF(double &v) { double dp = 1; bool neg = false, adp = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c) || c == '.'; c = gc()) { if (c == '.') adp = true; else if (adp) v += (c - '0') * (dp *= 0.1); else v = v * 10 + (c - '0'); } if (neg) v = -v; } template <class T, class U> inline void InputF(pair<T, U> &v) { InputF(v.first); InputF(v.second); } template <class T> inline void InputF(vector<T> &v) { for (auto &e : v) InputF(e); } template <class T> inline T InputF() { T v; InputF(v); return v; } inline string GetLine() { string v; char c; for (InputF(c); c != '\n' && c != '\0'; c = gc()) v += c; return v; } struct InputV { int n, m; InputV(int N) : n(N), m(0) {} InputV(pair<int, int> N) : n(N.first), m(N.second) {} template <class T> operator vector<T>() { vector<T> v(n); InputF(v); return v; } template <class T> operator vector<vector<T>>() { vector<vector<T>> v(n, vector<T>(m)); InputF(v); return v; } }; struct Input { template <class T> operator T() { return InputF<T>(); } int operator--(int) { int v; InputF(v); v--; return v; } InputV operator[](int n) { return InputV(n); } InputV operator[](pair<int, int> n) { return InputV(n); } void operator()() {} template <class H, class... T> void operator()(H &&h, T &&...t) { InputF(h); operator()(forward<T>(t)...); } template <class T> Input &operator,(T &&v) { InputF(v); return *this; } } in; #define input(T) InputF<T>() #define INT input(int) #define LL input(ll) #define STR input(string) #define inputs(T, ...) \ T __VA_ARGS__; \ in(__VA_ARGS__) #define ini(...) inputs(int, __VA_ARGS__) #define inl(...) inputs(ll, __VA_ARGS__) #define ins(...) inputs(string, __VA_ARGS__) // --- output --- // struct BoolStr { const char *t, *f; BoolStr(const char *_t, const char *_f) : t(_t), f(_f) {} } Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0"); struct DivStr { const char *d, *l; DivStr(const char *_d, const char *_l) : d(_d), l(_l) {} } spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"), no_endl(" ", ""); class Output { BoolStr B{Yes}; DivStr D{spc}; void p(int v) { if (v < 0) putchar_unlocked('-'), v = -v; char b[10]; int i = 0; while (v) b[i++] = '0' + v % 10, v /= 10; if (!i) b[i++] = '0'; while (i--) putchar_unlocked(b[i]); } void p(ll v) { if (v < 0) putchar_unlocked('-'), v = -v; char b[20]; int i = 0; while (v) b[i++] = '0' + v % 10, v /= 10; if (!i) b[i++] = '0'; while (i--) putchar_unlocked(b[i]); } void p(bool v) { p(v ? B.t : B.f); } void p(char v) { putchar_unlocked(v); } void p(const char *v) { fwrite_unlocked(v, 1, strlen(v), stdout); } void p(double v) { printf("%.20f", v); } void p(ld v) { printf("%.20Lf", v); } template <class T> void p(const T &v) { cout << v; } template <class T, class U> void p(const pair<T, U> &v) { p(v.first); p(D.d); p(v.second); } template <class T> void p(const vector<T> &v) { rep(i, sz(v)) { if (i) p(D.d); p(v[i]); } } template <class T> void p(const vector<vector<T>> &v) { rep(i, sz(v)) { if (i) p(D.l); p(v[i]); } } public: Output &operator()() { p(D.l); return *this; } template <class H> Output &operator()(H &&h) { p(h); p(D.l); return *this; } template <class H, class... T> Output &operator()(H &&h, T &&...t) { p(h); p(D.d); return operator()(forward<T>(t)...); } template <class... T> void exit(T &&...t) { operator()(forward<T>(t)...); std::exit(EXIT_SUCCESS); } Output &flush() { fflush_unlocked(stdout); return *this; } Output &set(const BoolStr &b) { B = b; return *this; } Output &set(const DivStr &d) { D = d; return *this; } Output &set(const char *t, const char *f) { B = BoolStr(t, f); return *this; } } out; // --- step --- // template <class T> struct Step { class It { T a, b, c; public: constexpr It() : a(T()), b(T()), c(T()) {} constexpr It(T _b, T _c, T _s) : a(_b), b(_c), c(_s) {} constexpr It &operator++() { --b; a += c; return *this; } constexpr It operator++(int) { It tmp = *this; --b; a += c; return tmp; } constexpr const T &operator*() const { return a; } constexpr const T *operator->() const { return &a; } constexpr bool operator==(const It &i) const { return b == i.b; } constexpr bool operator!=(const It &i) const { return !(b == i.b); } constexpr T start() const { return a; } constexpr T count() const { return b; } constexpr T step() const { return c; } }; constexpr Step(T b, T c, T s) : be(b, c, s) {} constexpr It begin() const { return be; } constexpr It end() const { return en; } constexpr T start() const { return be.start(); } constexpr T count() const { return be.count(); } constexpr T step() const { return be.step(); } constexpr T sum() const { return start() * count() + step() * (count() * (count() - 1) / 2); } operator vector<T>() const { return as_vector(); } template <class F> void each(const F &f) const { for (T i : *this) f(i); } vector<T> as_vector() const { vector<T> res; res.reserve(count()); each([&](T i) { res.push_back(i); }); return res; } template <class F, class U = decay_t<result_of_t<F(T)>>> auto map(const F &f) const { vector<U> res; res.reserve(count()); each([&](T i) { res.push_back(f(i)); }); return res; } template <class F> vector<T> select(const F &f) const { vector<T> res; each([&](T i) { if (f(i)) res.push_back(i); }); return res; } template <class F> int count_if(const F &f) const { int res = 0; each([&](T i) { if (f(i)) ++res; }); return res; } template <class F> T find_if(const F &f) const { for (T i : *this) if (f(i)) return i; return 0; } template <class F> auto max_by(const F &f) const { auto v = map(f); return *max_element(v.begin(), v.end()); } template <class F> auto min_by(const F &f) const { auto v = map(f); return *min_element(v.begin(), v.end()); } template <class F, class U = decay_t<result_of_t<F(T)>>> auto sum(const F &f) const { U res = 0; each([&](T i) { res += static_cast<U>(f(i)); }); return res; } using value_type = T; using iterator = It; private: It be, en; }; template <class T> inline constexpr auto step(T a) { return Step<T>(0, a, 1); } template <class T> inline constexpr auto step(T a, T b) { return Step<T>(a, b - a, 1); } template <class T> inline constexpr auto step(T a, T b, T c) { return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c); } // --- functions --- // inline namespace { template <class T> inline void Sort(T &a) { sort(all(a)); } template <class T> inline void RSort(T &a) { sort(rall(a)); } template <class T> inline T Sorted(T a) { Sort(a); return a; } template <class T> inline T RSorted(T a) { RSort(a); return a; } template <class T, class F> inline void Sort(T &a, const F &f) { sort(all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class F> inline void RSort(T &a, const F &f) { sort(rall(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T> inline void Reverse(T &a) { reverse(all(a)); } template <class T> inline void Unique(T &a) { a.erase(unique(all(a)), a.end()); } template <class T> inline void Rotate(T &a, int left) { rotate(a.begin(), a.begin() + left, a.end()); } template <class T> inline T Reversed(T a) { Reverse(a); return a; } template <class T> inline T Uniqued(T a) { Unique(a); return a; } template <class T> inline T Rotated(T a, int left) { Rotate(a, left); return a; } template <class T> inline auto Max(const T &a) { return *max_element(all(a)); } template <class T> inline auto Min(const T &a) { return *min_element(all(a)); } template <class T> inline int MaxPos(const T &a) { return max_element(all(a)) - a.begin(); } template <class T> inline int MinPos(const T &a) { return min_element(all(a)) - a.begin(); } template <class T, class F> inline auto Max(const T &a, const F &f) { return *max_element( all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class F> inline auto Min(const T &a, const F &f) { return *min_element( all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class U> inline int Count(const T &a, const U &v) { return count(all(a), v); } template <class T, class F> inline int CountIf(const T &a, const F &f) { return count_if(all(a), f); } template <class T, class U> inline int Find(const T &a, const U &v) { return find(all(a), v) - a.begin(); } template <class T, class F> inline int FindIf(const T &a, const F &f) { return find_if(all(a), f) - a.begin(); } template <class T, class U = typename T::value_type> inline U Sum(const T &a) { return accumulate(all(a), U()); } template <class T, class F> inline auto Sum(const T &v, const F &f) { return accumulate(next(v.begin()), v.end(), f(v.front()), [&](auto a, auto b) { return a + f(b); }); } template <class T, class U> inline int Lower(const T &a, const U &v) { return lower_bound(all(a), v) - a.begin(); } template <class T, class U> inline int Upper(const T &a, const U &v) { return upper_bound(all(a), v) - a.begin(); } template <class T, class F> inline void RemoveIf(T &a, const F &f) { a.erase(remove_if(all(a), f), a.end()); } template <class F> inline auto Vector(size_t size, const F &f) { vector<decay_t<result_of_t<F(size_t)>>> res(size); for (size_t i = 0; i < size; ++i) res[i] = f(i); return res; } template <class T> inline auto Grid(size_t h, size_t w, const T &v = T()) { return vector<vector<T>>(h, vector<T>(w, v)); } template <class T> inline auto Slice(const T &v, size_t i, size_t len) { return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T(); } template <class T, class F> inline auto Each(const T &v, const F &f) { for (auto &i : v) f(i); } template <class T, class F> inline auto Select(const T &v, const F &f) { T res; for (const auto &e : v) if (f(e)) res.push_back(e); return res; } template <class T, class F> inline auto Map(const T &v, const F &f) { vector<decay_t<result_of_t<F(typename T::value_type)>>> res(v.size()); size_t i = 0; for (const auto &e : v) res[i++] = f(e); return res; } template <class T, class F> inline auto MapIndex(const T &v, const F &f) { vector<decay_t<result_of_t<F(size_t, typename T::value_type)>>> res(v.size()); size_t i = 0; for (auto it = v.begin(); it != v.end(); ++it, ++i) res[i] = f(i, *it); return res; } template <class T, class F> inline auto TrueIndex(const T &v, const F &f) { vector<size_t> res; for (size_t i = 0; i < v.size(); ++i) if (f(v[i])) res.push_back(i); return res; } inline string operator*(string s, size_t n) { string ret; for (size_t i = 0; i < n; ++i) ret += s; return ret; } template <class T> inline T Ceil(T n, T m) { return (n + m - 1) / m; } template <class T> inline T Ceil2(T n, T m) { return Ceil(n, m) * m; } template <class T> inline T Tri(T n) { return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1); } template <class T> inline T nC2(T n) { return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1); } template <class T> inline T Mid(const T &l, const T &r) { return l + (r - l) / 2; } inline int pop_count(int n) { return bitset<32>(n).count(); } inline int pop_count(ll n) { return bitset<64>(n).count(); } template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool inRange(const T &v, const T &min, const T &max) { return min <= v && v < max; } template <class T = ll> inline T BIT(int b) { return T(1) << b; } template <class T> inline T Gcd(T n, T m) { return m ? Gcd(m, n % m) : n; } template <class T> inline T Lcm(T n, T m) { return n / Gcd(n, m) * m; } template <class T, class U = typename T::value_type> inline U Gcdv(const T &v) { return accumulate(next(v.begin()), v.end(), U(*v.begin()), Gcd<U>); } template <class T, class U = typename T::value_type> inline U Lcmv(const T &v) { return accumulate(next(v.begin()), v.end(), U(*v.begin()), Lcm<U>); } template <class T> inline T Pow(T a, T n) { T r = 1; while (n > 0) { if (n & 1) r *= a; a *= a; n /= 2; } return r; } template <class T> inline T Powmod(T a, T n, T m = MOD) { T r = 1; while (n > 0) { if (n & 1) r = r * a % m, n--; else a = a * a % m, n /= 2; } return r; } } // namespace // --- dump --- // #if __has_include("dump.hpp") #include "dump.hpp" #else #define dump(...) ((void)0) #endif // ---------------------------------------------------------------- // int main() { ini(m); VI d(m); VL c(m); rep(i, m) in(d[i], c[i]); ll ans = 0; auto next = [&](int d1, int d2) { if (d1 + d2 < 10) { return make_pair(d1 + d2, 1); } else { int N = d1 + d2; return make_pair(N % 10 + N / 10, 2); } }; function<int(int, int)> dfs = [&](int digit, ll cnt) { if (cnt == 1) { return digit; } else if (cnt % 2 == 0) { int N, C; tie(N, C) = next(digit, digit); ans += C * (cnt / 2); return dfs(N, cnt / 2); } else { int N, C; tie(N, C) = next(digit, digit); ans += C * (cnt / 2); int res = dfs(N, cnt / 2); int N2, C2; tie(N2, C2) = next(res, digit); ans += C2; return N2; } }; VI D(m); rep(i, m) { D[i] = dfs(d[i], c[i]); } while (sz(D) > 1) { int e1 = D.back(); D.pop_back(); int e2 = D.back(); D.pop_back(); int N, C; tie(N, C) = next(e1, e2); ans += C; D.push_back(N); } out(ans); }
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rfor(i, m, n) for (int i = (m); i >= (n); --i) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r) using namespace std; using ll = long long; using ld = long double; using VB = vector<bool>; using VVB = vector<VB>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using VS = vector<string>; using VD = vector<ld>; using PII = pair<int, int>; using VP = vector<PII>; using PLL = pair<ll, ll>; using VPL = vector<PLL>; template <class T> using PQ = priority_queue<T>; template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = (int)1e9; constexpr ll inf_ll = (ll)1e18, MOD = 1000000007; constexpr ld PI = M_PI, EPS = 1e-12; // --- input --- // #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #define putchar_unlocked _putchar_nolock #define fwrite_unlocked fwrite #define fflush_unlocked _fflush_nolock #endif inline int gc() { return getchar_unlocked(); } template <class T> inline void InputF(T &v) { cin >> v; } inline void InputF(char &v) { while (isspace(v = gc())) ; } inline void InputF(bool &v) { char c; InputF(c); v = c != '0'; } inline void InputF(string &v) { v.clear(); char c; for (InputF(c); !isspace(c); c = gc()) v += c; } inline void InputF(int &v) { bool neg = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (neg) v = -v; } inline void InputF(long long &v) { bool neg = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c); c = gc()) v = v * 10 + (c - '0'); if (neg) v = -v; } inline void InputF(double &v) { double dp = 1; bool neg = false, adp = false; v = 0; char c; InputF(c); if (c == '-') { neg = true; c = gc(); } for (; isdigit(c) || c == '.'; c = gc()) { if (c == '.') adp = true; else if (adp) v += (c - '0') * (dp *= 0.1); else v = v * 10 + (c - '0'); } if (neg) v = -v; } template <class T, class U> inline void InputF(pair<T, U> &v) { InputF(v.first); InputF(v.second); } template <class T> inline void InputF(vector<T> &v) { for (auto &e : v) InputF(e); } template <class T> inline T InputF() { T v; InputF(v); return v; } inline string GetLine() { string v; char c; for (InputF(c); c != '\n' && c != '\0'; c = gc()) v += c; return v; } struct InputV { int n, m; InputV(int N) : n(N), m(0) {} InputV(pair<int, int> N) : n(N.first), m(N.second) {} template <class T> operator vector<T>() { vector<T> v(n); InputF(v); return v; } template <class T> operator vector<vector<T>>() { vector<vector<T>> v(n, vector<T>(m)); InputF(v); return v; } }; struct Input { template <class T> operator T() { return InputF<T>(); } int operator--(int) { int v; InputF(v); v--; return v; } InputV operator[](int n) { return InputV(n); } InputV operator[](pair<int, int> n) { return InputV(n); } void operator()() {} template <class H, class... T> void operator()(H &&h, T &&...t) { InputF(h); operator()(forward<T>(t)...); } template <class T> Input &operator,(T &&v) { InputF(v); return *this; } } in; #define input(T) InputF<T>() #define INT input(int) #define LL input(ll) #define STR input(string) #define inputs(T, ...) \ T __VA_ARGS__; \ in(__VA_ARGS__) #define ini(...) inputs(int, __VA_ARGS__) #define inl(...) inputs(ll, __VA_ARGS__) #define ins(...) inputs(string, __VA_ARGS__) // --- output --- // struct BoolStr { const char *t, *f; BoolStr(const char *_t, const char *_f) : t(_t), f(_f) {} } Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0"); struct DivStr { const char *d, *l; DivStr(const char *_d, const char *_l) : d(_d), l(_l) {} } spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"), no_endl(" ", ""); class Output { BoolStr B{Yes}; DivStr D{spc}; void p(int v) { if (v < 0) putchar_unlocked('-'), v = -v; char b[10]; int i = 0; while (v) b[i++] = '0' + v % 10, v /= 10; if (!i) b[i++] = '0'; while (i--) putchar_unlocked(b[i]); } void p(ll v) { if (v < 0) putchar_unlocked('-'), v = -v; char b[20]; int i = 0; while (v) b[i++] = '0' + v % 10, v /= 10; if (!i) b[i++] = '0'; while (i--) putchar_unlocked(b[i]); } void p(bool v) { p(v ? B.t : B.f); } void p(char v) { putchar_unlocked(v); } void p(const char *v) { fwrite_unlocked(v, 1, strlen(v), stdout); } void p(double v) { printf("%.20f", v); } void p(ld v) { printf("%.20Lf", v); } template <class T> void p(const T &v) { cout << v; } template <class T, class U> void p(const pair<T, U> &v) { p(v.first); p(D.d); p(v.second); } template <class T> void p(const vector<T> &v) { rep(i, sz(v)) { if (i) p(D.d); p(v[i]); } } template <class T> void p(const vector<vector<T>> &v) { rep(i, sz(v)) { if (i) p(D.l); p(v[i]); } } public: Output &operator()() { p(D.l); return *this; } template <class H> Output &operator()(H &&h) { p(h); p(D.l); return *this; } template <class H, class... T> Output &operator()(H &&h, T &&...t) { p(h); p(D.d); return operator()(forward<T>(t)...); } template <class... T> void exit(T &&...t) { operator()(forward<T>(t)...); std::exit(EXIT_SUCCESS); } Output &flush() { fflush_unlocked(stdout); return *this; } Output &set(const BoolStr &b) { B = b; return *this; } Output &set(const DivStr &d) { D = d; return *this; } Output &set(const char *t, const char *f) { B = BoolStr(t, f); return *this; } } out; // --- step --- // template <class T> struct Step { class It { T a, b, c; public: constexpr It() : a(T()), b(T()), c(T()) {} constexpr It(T _b, T _c, T _s) : a(_b), b(_c), c(_s) {} constexpr It &operator++() { --b; a += c; return *this; } constexpr It operator++(int) { It tmp = *this; --b; a += c; return tmp; } constexpr const T &operator*() const { return a; } constexpr const T *operator->() const { return &a; } constexpr bool operator==(const It &i) const { return b == i.b; } constexpr bool operator!=(const It &i) const { return !(b == i.b); } constexpr T start() const { return a; } constexpr T count() const { return b; } constexpr T step() const { return c; } }; constexpr Step(T b, T c, T s) : be(b, c, s) {} constexpr It begin() const { return be; } constexpr It end() const { return en; } constexpr T start() const { return be.start(); } constexpr T count() const { return be.count(); } constexpr T step() const { return be.step(); } constexpr T sum() const { return start() * count() + step() * (count() * (count() - 1) / 2); } operator vector<T>() const { return as_vector(); } template <class F> void each(const F &f) const { for (T i : *this) f(i); } vector<T> as_vector() const { vector<T> res; res.reserve(count()); each([&](T i) { res.push_back(i); }); return res; } template <class F, class U = decay_t<result_of_t<F(T)>>> auto map(const F &f) const { vector<U> res; res.reserve(count()); each([&](T i) { res.push_back(f(i)); }); return res; } template <class F> vector<T> select(const F &f) const { vector<T> res; each([&](T i) { if (f(i)) res.push_back(i); }); return res; } template <class F> int count_if(const F &f) const { int res = 0; each([&](T i) { if (f(i)) ++res; }); return res; } template <class F> T find_if(const F &f) const { for (T i : *this) if (f(i)) return i; return 0; } template <class F> auto max_by(const F &f) const { auto v = map(f); return *max_element(v.begin(), v.end()); } template <class F> auto min_by(const F &f) const { auto v = map(f); return *min_element(v.begin(), v.end()); } template <class F, class U = decay_t<result_of_t<F(T)>>> auto sum(const F &f) const { U res = 0; each([&](T i) { res += static_cast<U>(f(i)); }); return res; } using value_type = T; using iterator = It; private: It be, en; }; template <class T> inline constexpr auto step(T a) { return Step<T>(0, a, 1); } template <class T> inline constexpr auto step(T a, T b) { return Step<T>(a, b - a, 1); } template <class T> inline constexpr auto step(T a, T b, T c) { return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c); } // --- functions --- // inline namespace { template <class T> inline void Sort(T &a) { sort(all(a)); } template <class T> inline void RSort(T &a) { sort(rall(a)); } template <class T> inline T Sorted(T a) { Sort(a); return a; } template <class T> inline T RSorted(T a) { RSort(a); return a; } template <class T, class F> inline void Sort(T &a, const F &f) { sort(all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class F> inline void RSort(T &a, const F &f) { sort(rall(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T> inline void Reverse(T &a) { reverse(all(a)); } template <class T> inline void Unique(T &a) { a.erase(unique(all(a)), a.end()); } template <class T> inline void Rotate(T &a, int left) { rotate(a.begin(), a.begin() + left, a.end()); } template <class T> inline T Reversed(T a) { Reverse(a); return a; } template <class T> inline T Uniqued(T a) { Unique(a); return a; } template <class T> inline T Rotated(T a, int left) { Rotate(a, left); return a; } template <class T> inline auto Max(const T &a) { return *max_element(all(a)); } template <class T> inline auto Min(const T &a) { return *min_element(all(a)); } template <class T> inline int MaxPos(const T &a) { return max_element(all(a)) - a.begin(); } template <class T> inline int MinPos(const T &a) { return min_element(all(a)) - a.begin(); } template <class T, class F> inline auto Max(const T &a, const F &f) { return *max_element( all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class F> inline auto Min(const T &a, const F &f) { return *min_element( all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); }); } template <class T, class U> inline int Count(const T &a, const U &v) { return count(all(a), v); } template <class T, class F> inline int CountIf(const T &a, const F &f) { return count_if(all(a), f); } template <class T, class U> inline int Find(const T &a, const U &v) { return find(all(a), v) - a.begin(); } template <class T, class F> inline int FindIf(const T &a, const F &f) { return find_if(all(a), f) - a.begin(); } template <class T, class U = typename T::value_type> inline U Sum(const T &a) { return accumulate(all(a), U()); } template <class T, class F> inline auto Sum(const T &v, const F &f) { return accumulate(next(v.begin()), v.end(), f(v.front()), [&](auto a, auto b) { return a + f(b); }); } template <class T, class U> inline int Lower(const T &a, const U &v) { return lower_bound(all(a), v) - a.begin(); } template <class T, class U> inline int Upper(const T &a, const U &v) { return upper_bound(all(a), v) - a.begin(); } template <class T, class F> inline void RemoveIf(T &a, const F &f) { a.erase(remove_if(all(a), f), a.end()); } template <class F> inline auto Vector(size_t size, const F &f) { vector<decay_t<result_of_t<F(size_t)>>> res(size); for (size_t i = 0; i < size; ++i) res[i] = f(i); return res; } template <class T> inline auto Grid(size_t h, size_t w, const T &v = T()) { return vector<vector<T>>(h, vector<T>(w, v)); } template <class T> inline auto Slice(const T &v, size_t i, size_t len) { return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T(); } template <class T, class F> inline auto Each(const T &v, const F &f) { for (auto &i : v) f(i); } template <class T, class F> inline auto Select(const T &v, const F &f) { T res; for (const auto &e : v) if (f(e)) res.push_back(e); return res; } template <class T, class F> inline auto Map(const T &v, const F &f) { vector<decay_t<result_of_t<F(typename T::value_type)>>> res(v.size()); size_t i = 0; for (const auto &e : v) res[i++] = f(e); return res; } template <class T, class F> inline auto MapIndex(const T &v, const F &f) { vector<decay_t<result_of_t<F(size_t, typename T::value_type)>>> res(v.size()); size_t i = 0; for (auto it = v.begin(); it != v.end(); ++it, ++i) res[i] = f(i, *it); return res; } template <class T, class F> inline auto TrueIndex(const T &v, const F &f) { vector<size_t> res; for (size_t i = 0; i < v.size(); ++i) if (f(v[i])) res.push_back(i); return res; } inline string operator*(string s, size_t n) { string ret; for (size_t i = 0; i < n; ++i) ret += s; return ret; } template <class T> inline T Ceil(T n, T m) { return (n + m - 1) / m; } template <class T> inline T Ceil2(T n, T m) { return Ceil(n, m) * m; } template <class T> inline T Tri(T n) { return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1); } template <class T> inline T nC2(T n) { return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1); } template <class T> inline T Mid(const T &l, const T &r) { return l + (r - l) / 2; } inline int pop_count(int n) { return bitset<32>(n).count(); } inline int pop_count(ll n) { return bitset<64>(n).count(); } template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool inRange(const T &v, const T &min, const T &max) { return min <= v && v < max; } template <class T = ll> inline T BIT(int b) { return T(1) << b; } template <class T> inline T Gcd(T n, T m) { return m ? Gcd(m, n % m) : n; } template <class T> inline T Lcm(T n, T m) { return n / Gcd(n, m) * m; } template <class T, class U = typename T::value_type> inline U Gcdv(const T &v) { return accumulate(next(v.begin()), v.end(), U(*v.begin()), Gcd<U>); } template <class T, class U = typename T::value_type> inline U Lcmv(const T &v) { return accumulate(next(v.begin()), v.end(), U(*v.begin()), Lcm<U>); } template <class T> inline T Pow(T a, T n) { T r = 1; while (n > 0) { if (n & 1) r *= a; a *= a; n /= 2; } return r; } template <class T> inline T Powmod(T a, T n, T m = MOD) { T r = 1; while (n > 0) { if (n & 1) r = r * a % m, n--; else a = a * a % m, n /= 2; } return r; } } // namespace // --- dump --- // #if __has_include("dump.hpp") #include "dump.hpp" #else #define dump(...) ((void)0) #endif // ---------------------------------------------------------------- // int main() { ini(m); VI d(m); VL c(m); rep(i, m) in(d[i], c[i]); ll ans = 0; auto next = [&](int d1, int d2) { if (d1 + d2 < 10) { return make_pair(d1 + d2, 1); } else { int N = d1 + d2; return make_pair(N % 10 + N / 10, 2); } }; function<int(int, ll)> dfs = [&](int digit, ll cnt) { if (cnt == 1) { return digit; } else if (cnt % 2 == 0) { int N, C; tie(N, C) = next(digit, digit); ans += C * (cnt / 2); return dfs(N, cnt / 2); } else { int N, C; tie(N, C) = next(digit, digit); ans += C * (cnt / 2); int res = dfs(N, cnt / 2); int N2, C2; tie(N2, C2) = next(res, digit); ans += C2; return N2; } }; VI D(m); rep(i, m) { D[i] = dfs(d[i], c[i]); } while (sz(D) > 1) { int e1 = D.back(); D.pop_back(); int e2 = D.back(); D.pop_back(); int N, C; tie(N, C) = next(e1, e2); ans += C; D.push_back(N); } out(ans); }
replace
593
594
593
594
0
p02856
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807 template <class T> using vec = std::vector<T>; template <class T> using vec2 = vec<vec<T>>; template <class T> using vec3 = vec<vec<vec<T>>>; // #define DEBUG void pushAsDigits(vec<int> &v, ll num) { if (num == 0) { v.push_back(0); return; } // num > 0 ll tens = 1; while (tens <= num) { tens *= 10; } // tens > num tens /= 10; // tens <= num while (tens > 0) { v.push_back(num / tens); num %= tens; tens /= 10; } } struct Result { vector<int> seq; ll cnt; }; Result compress(int dig, ll num) { if (num == 0) { return Result{vector<int>{}, 0}; } if (num < 2) { assert(num == 1); return Result{vector<int>{dig}, 0}; } if (num % 2 == 1) { auto res = compress(dig, num - 1); res.seq.push_back(dig); return res; } if (dig * 2 < 10) { auto res = compress(dig * 2, num / 2); return Result{res.seq, res.cnt + num / 2}; } else { auto res1 = compress((dig * 2) / 10, num / 2); auto res2 = compress((dig * 2) % 10, num / 2); res1.seq.insert(res1.seq.end(), res2.seq.begin(), res2.seq.end()); return Result{res1.seq, res1.cnt + res2.cnt + num / 2}; } } void solve(long long M, std::vector<long long> d, std::vector<long long> c) { ll cnt = 0; vec<int> people; // 各数の出現回数をしらべる vector<int> appr(10, 0); for (int i = 0; i < M; i++) { appr[d[i]] += c[i]; } for (int i = 0; i < 10; i++) { if (appr[i] == 0) { continue; } auto res = compress(i, appr[i]); cnt += res.cnt; people.insert(people.end(), res.seq.begin(), res.seq.end()); } // for(int i=0; i < M; i++){ // // for(int j=0; j < c[i]; j++){ // // people.push_back(d[i]); // // } // auto res = compress(d[i], c[i]); // #ifdef DEBUG // printf("*START: hoge\n"); // for(auto iter: res.seq){ // cout << iter << " "; // } // cout << endl; // cout << res.cnt << endl; // printf("*END: hoge\n"); // #endif // cnt += res.cnt; // people.insert(people.end(), res.seq.begin(), res.seq.end()); // } while (people.size() > 1) { int N = people.size(); int next = people[N - 2] + people[N - 1]; people.erase(people.begin() + (N - 1)); people.erase(people.begin() + (N - 2)); if (next < 10) { people.push_back(next); } else { people.push_back(next / 10); people.push_back(next % 10); } #ifdef DEBUG printf("*START: rem\n"); cout << people.size() << endl; printf("*END: rem\n"); #endif cnt++; } cout << cnt << endl; } // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { long long M; scanf("%lld", &M); std::vector<long long> d(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &d[i]); scanf("%lld", &c[i]); } solve(M, std::move(d), std::move(c)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807 template <class T> using vec = std::vector<T>; template <class T> using vec2 = vec<vec<T>>; template <class T> using vec3 = vec<vec<vec<T>>>; // #define DEBUG void pushAsDigits(vec<int> &v, ll num) { if (num == 0) { v.push_back(0); return; } // num > 0 ll tens = 1; while (tens <= num) { tens *= 10; } // tens > num tens /= 10; // tens <= num while (tens > 0) { v.push_back(num / tens); num %= tens; tens /= 10; } } struct Result { vector<int> seq; ll cnt; }; Result compress(int dig, ll num) { if (num == 0) { return Result{vector<int>{}, 0}; } if (num < 2) { assert(num == 1); return Result{vector<int>{dig}, 0}; } if (num % 2 == 1) { auto res = compress(dig, num - 1); res.seq.push_back(dig); return res; } if (dig * 2 < 10) { auto res = compress(dig * 2, num / 2); return Result{res.seq, res.cnt + num / 2}; } else { auto res1 = compress((dig * 2) / 10, num / 2); auto res2 = compress((dig * 2) % 10, num / 2); res1.seq.insert(res1.seq.end(), res2.seq.begin(), res2.seq.end()); return Result{res1.seq, res1.cnt + res2.cnt + num / 2}; } } void solve(long long M, std::vector<long long> d, std::vector<long long> c) { ll cnt = 0; vec<int> people; // 各数の出現回数をしらべる vector<ll> appr(10, 0); for (int i = 0; i < M; i++) { appr[d[i]] += c[i]; } for (int i = 0; i < 10; i++) { if (appr[i] == 0) { continue; } auto res = compress(i, appr[i]); cnt += res.cnt; people.insert(people.end(), res.seq.begin(), res.seq.end()); } // for(int i=0; i < M; i++){ // // for(int j=0; j < c[i]; j++){ // // people.push_back(d[i]); // // } // auto res = compress(d[i], c[i]); // #ifdef DEBUG // printf("*START: hoge\n"); // for(auto iter: res.seq){ // cout << iter << " "; // } // cout << endl; // cout << res.cnt << endl; // printf("*END: hoge\n"); // #endif // cnt += res.cnt; // people.insert(people.end(), res.seq.begin(), res.seq.end()); // } while (people.size() > 1) { int N = people.size(); int next = people[N - 2] + people[N - 1]; people.erase(people.begin() + (N - 1)); people.erase(people.begin() + (N - 2)); if (next < 10) { people.push_back(next); } else { people.push_back(next / 10); people.push_back(next % 10); } #ifdef DEBUG printf("*START: rem\n"); cout << people.size() << endl; printf("*END: rem\n"); #endif cnt++; } cout << cnt << endl; } // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { long long M; scanf("%lld", &M); std::vector<long long> d(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &d[i]); scanf("%lld", &c[i]); } solve(M, std::move(d), std::move(c)); return 0; }
replace
67
68
67
68
0
p02856
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9 + 7; ll c[100100], d[100100]; int main() { int m; cin >> m; rep(i, m) cin >> d[i] >> c[i]; ll s = 0, len = 0; rep(i, m) { s += c[i] * d[i]; len += c[i]; } ll ans = (len - 1) + ((s - 1) / 9); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9 + 7; ll c[200100], d[200100]; int main() { int m; cin >> m; rep(i, m) cin >> d[i] >> c[i]; ll s = 0, len = 0; rep(i, m) { s += c[i] * d[i]; len += c[i]; } ll ans = (len - 1) + ((s - 1) / 9); cout << ans << endl; return 0; }
replace
8
9
8
9
0
p02856
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } PLL solve(int64 x, int64 c) { if (x == 0) return PLL(x, c - 1); int64 cnt = 0, now = x, i; for (i = 1; i < c; i++) { now += x; cnt++; while (now > 9) { now = now / 10 + now % 10; cnt++; } if (now == x) break; } if (i == c - 1) return PLL(now, cnt); int64 loop = cnt; cnt = 0; while (c >= loop) { cnt += c / (i + 1) * loop; c = c / (i + 1) + c % (i + 1); } now = x; REP(i, c - 1) { cnt++; now = now + x; while (now > 9) { cnt++; now = now / 10 + now % 10; } } return PLL(now, cnt); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int64 M; cin >> M; vector<int64> d(M), c(M), a(M); int64 res = 0; REP(i, M) { cin >> d[i] >> c[i]; PLL ret = solve(d[i], c[i]); // cout << ret.sc << " " << ret.fs << endl; res += ret.sc; a[i] = ret.fs; // cout << ret.fs << " " << ret.sc << endl; } int64 now = a[0]; FOR(i, 1, M) { now += a[i]; res++; while (now > 9) { now = (now % 10) + now / 10; res++; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } PLL solve(int64 x, int64 c) { if (x == 0) return PLL(x, c - 1); int64 cnt = 0, now = x, i; for (i = 1; i < c; i++) { now += x; cnt++; while (now > 9) { now = now / 10 + now % 10; cnt++; } if (now == x) break; } if (i == c - 1) return PLL(now, cnt); int64 loop = cnt; cnt = 0; while (c >= i + 1) { cnt += c / (i + 1) * loop; c = c / (i + 1) + c % (i + 1); } now = x; REP(i, c - 1) { cnt++; now = now + x; while (now > 9) { cnt++; now = now / 10 + now % 10; } } return PLL(now, cnt); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int64 M; cin >> M; vector<int64> d(M), c(M), a(M); int64 res = 0; REP(i, M) { cin >> d[i] >> c[i]; PLL ret = solve(d[i], c[i]); // cout << ret.sc << " " << ret.fs << endl; res += ret.sc; a[i] = ret.fs; // cout << ret.fs << " " << ret.sc << endl; } int64 now = a[0]; FOR(i, 1, M) { now += a[i]; res++; while (now > 9) { now = (now % 10) + now / 10; res++; } } cout << res << endl; }
replace
64
65
64
65
TLE
p02856
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; }; template <class T> struct _vec<T, 0> { using type = T; }; template <class T, size_t D> using vec = typename _vec<T, D>::type; 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 <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; } template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ pair<ll, int> naive(int a, int b, ll c) { ll res = 0; while (c > 0) { int s = a + b; ++res; --c; while (s > 9) { int ns = (s / 10) + (s % 10); ++res; s = ns; } a = s; } return {res, a}; } pair<ll, int> solve(int a, int b, ll c) { ll res = 0; vector<ll> mem_c(10, -1), mem_res(10, -1); while (c > 0) { if (mem_c[a] != -1) { ll use_c = mem_c[a] - c; ll cost = res - mem_res[a]; ll cnt = c / use_c; res += cnt * cost; c -= cnt * use_c; auto v = naive(a, b, c); res += v.fst; a = v.snd; break; } int s = a + b; ++res; --c; while (s > 9) { int ns = (s / 10) + (s % 10); ++res; s = ns; } a = s; } return {res, a}; } int main() { #ifdef DEBUG ifstream ifs("in.txt"); cin.rdbuf(ifs.rdbuf()); #endif int M; while (cin >> M) { ll res = 0; int a = 0; for (int i = 0; i < M; i++) { int d; ll c; cin >> d >> c; auto r = solve(a, d, c); res += r.fst; a = r.snd; } cout << res - 1 << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; }; template <class T> struct _vec<T, 0> { using type = T; }; template <class T, size_t D> using vec = typename _vec<T, D>::type; 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 <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; } template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ pair<ll, int> naive(int a, int b, ll c) { ll res = 0; while (c > 0) { int s = a + b; ++res; --c; while (s > 9) { int ns = (s / 10) + (s % 10); ++res; s = ns; } a = s; } return {res, a}; } pair<ll, int> solve(int a, int b, ll c) { ll res = 0; vector<ll> mem_c(10, -1), mem_res(10, -1); while (c > 0) { if (mem_c[a] != -1) { ll use_c = mem_c[a] - c; ll cost = res - mem_res[a]; ll cnt = c / use_c; res += cnt * cost; c -= cnt * use_c; auto v = naive(a, b, c); res += v.fst; a = v.snd; break; } mem_c[a] = c; mem_res[a] = res; int s = a + b; ++res; --c; while (s > 9) { int ns = (s / 10) + (s % 10); ++res; s = ns; } a = s; } return {res, a}; } int main() { #ifdef DEBUG ifstream ifs("in.txt"); cin.rdbuf(ifs.rdbuf()); #endif int M; while (cin >> M) { ll res = 0; int a = 0; for (int i = 0; i < M; i++) { int d; ll c; cin >> d >> c; auto r = solve(a, d, c); res += r.fst; a = r.snd; } cout << res - 1 << endl; } return 0; }
insert
64
64
64
66
TLE
p02856
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int sum, tot; int d[100001]; int c[100001]; int n; signed main() { int n; scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld%lld", &c[i], &d[i]); tot += d[i]; sum += d[i] * c[i]; } printf("%lld", (sum - 1) / 9 + tot - 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int sum, tot; int d[1000001]; int c[1000001]; int n; signed main() { int n; scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld%lld", &c[i], &d[i]); tot += d[i]; sum += d[i] * c[i]; } printf("%lld", (sum - 1) / 9 + tot - 1); return 0; }
replace
4
6
4
6
0
p02856
C++
Time Limit Exceeded
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <limits> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); long long ans = -1; long long sum = 0; for (int i = 0; i < n; i++) { long long d, c; scanf("%lld%lld", &d, &c); ans += c; sum += d * c; } while (sum) { ans += sum / 10; sum = sum / 10 + sum % 10; } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <limits> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); long long ans = -1; long long sum = 0; for (int i = 0; i < n; i++) { long long d, c; scanf("%lld%lld", &d, &c); ans += c; sum += d * c; } while (sum >= 10) { ans += sum / 10; sum = sum / 10 + sum % 10; } printf("%lld\n", ans); return 0; }
replace
33
34
33
34
TLE
p02856
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <ciso646> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define inf 0x3f3f3f3f3f3f3f3f #define ALL(a) (a).begin(), (a).end() #define DEBUG(x) // cerr<<#x<<": "<<x<<endl #define ll long long #define ull unsigned long long using pii = pair<ll, ll>; #define eps 1e-14 #define SETUP \ cin.tie(0), ios::sync_with_stdio(false), \ cout << setprecision(15) << std::fixed; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) template <class T> using vec2 = std::vector<vector<T>>; //// bit //// #ifdef _MSC_VER #ifdef _WIN32 inline unsigned int __builtin_ctz(unsigned int x) { unsigned long r; _BitScanForward(&r, x); return r; } inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; } inline unsigned int __builtin_ffs(unsigned int x) { unsigned long r; return _BitScanForward(&r, x) ? r + 1 : 0; } // inline unsigned int __builtin_popcount(unsigned int x){ return __popcnt(x); } #ifdef _WIN64 inline unsigned long long __builtin_ctzll(unsigned long long x) { unsigned long r; _BitScanForward64(&r, x); return r; } inline unsigned long long __builtin_clzll(unsigned long long x) { unsigned long r; _BitScanReverse64(&r, x); return 63 - r; } inline unsigned long long __builtin_ffsll(unsigned long long x) { unsigned long r; return _BitScanForward64(&r, x) ? r + 1 : 0; } inline unsigned long long __builtin_popcountll(unsigned long long x) { return __popcnt64(x); } #else inline unsigned int hidword(unsigned long long x) { return static_cast<unsigned int>(x >> 32); } inline unsigned int lodword(unsigned long long x) { return static_cast<unsigned int>(x & 0xFFFFFFFF); } inline unsigned long long __builtin_ctzll(unsigned long long x) { return lodword(x) ? __builtin_ctz(lodword(x)) : __builtin_ctz(hidword(x)) + 32; } inline unsigned long long __builtin_clzll(unsigned long long x) { return hidword(x) ? __builtin_clz(hidword(x)) : __builtin_clz(lodword(x)) + 32; } inline unsigned long long __builtin_ffsll(unsigned long long x) { return lodword(x) ? __builtin_ffs(lodword(x)) : hidword(x) ? __builtin_ffs(hidword(x)) + 32 : 0; } // inline unsigned long long __builtin_popcountll(unsigned long long x) { return // __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); } #endif // _WIN64 #endif // _WIN32 #endif // _MSC_VER namespace { struct input_returnner { ll N; input_returnner(ll N_ = 0) : N(N_) {} template <typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); } template <typename T> operator T() const { T res; cin >> res; return res; } template <typename T> T operator-(T right) { return T(input_returnner()) - right; } template <typename T> T operator+(T right) { return T(input_returnner()) + right; } template <typename T> T operator*(T right) { return T(input_returnner()) * right; } template <typename T> T operator/(T right) { return T(input_returnner()) / right; } template <typename T> T operator<<(T right) { return T(input_returnner()) << right; } template <typename T> T operator>>(T right) { return T(input_returnner()) >> right; } }; template <typename T> input_returnner in() { return in<T>(); } input_returnner in() { return input_returnner(); } input_returnner in(ll N) { return std::move(input_returnner(N)); } } // namespace template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> struct is_vector : std::false_type {}; template <typename T> struct is_vector<std::vector<T>> : std::true_type {}; template <typename T> constexpr bool is_vector_v = is_vector<T>::value; template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { for (int i = 0; i < v.size(); ++i) { out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", ")); } } return out; } namespace std { // ref: // https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set template <class T> inline void hash_combine(std::size_t &seed, T const &v) { seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } // Recursive template code derived from Matthieu M. template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1> struct HashValueImpl { static void apply(size_t &seed, Tuple const &tuple) { HashValueImpl<Tuple, Index - 1>::apply(seed, tuple); hash_combine(seed, std::get<Index>(tuple)); } }; template <class Tuple> struct HashValueImpl<Tuple, 0> { static void apply(size_t &seed, Tuple const &tuple) { hash_combine(seed, std::get<0>(tuple)); } }; template <typename... TT> struct hash<std::tuple<TT...>> { size_t operator()(std::tuple<TT...> const &tt) const { size_t seed = 0; HashValueImpl<std::tuple<TT...>>::apply(seed, tt); return seed; } }; template <class T, class U> class hash<std::pair<T, U>> { public: size_t operator()(const std::pair<T, U> &x) const { return hash<std::tuple<T, U>>()(std::tie(x.first, x.second)); } }; } // namespace std // ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple namespace aux { template <std::size_t...> struct seq {}; template <std::size_t N, std::size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, std::size_t... Is> void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using swallow = int[]; (void)swallow{0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...}; } } // namespace aux template <class Ch, class Tr, class... Args> auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t) -> std::basic_ostream<Ch, Tr> & { os << "("; aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>()); return os << ")"; } template <class S, class T> std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } // ref: // https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp template <typename T> struct reversion_wrapper { T &iterable; }; template <typename T> auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); } template <typename T> auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); } template <typename T> reversion_wrapper<T> REV(T &&iterable) { return {iterable}; } template <class T> bool inside(T left, T val, T right) { return left <= val and val < right; } template <class T> T bitCount(T num) { T res = 0; while (num > 0) { if (num & 1) ++res; num >>= 1; } return res; } ll MOD = 1e9 + 7; // ll MOD = 998244353; void solve(); signed main() { SETUP; #ifdef _DEBUG while (true) { #endif solve(); #ifdef _DEBUG cout << "-------" << endl; } #endif #ifdef _DEBUG system("pause"); #endif return 0; } #define int ll struct mint { int64_t value; mint() : value(0) {} mint(int64_t value_) : value(value_ % MOD) {} inline mint &operator+=(const mint &rhs) { value += rhs.value; if (value >= MOD) { value -= MOD; } return *this; } inline mint &operator-=(const mint &rhs) { value -= rhs.value; if (value < 0) { value += MOD; } return *this; } inline mint &operator*=(const mint &rhs) { value *= rhs.value; value %= MOD; return *this; } inline mint &operator%=(const mint &rhs) { return *this; } }; // x^n % mod // O(log n) mint mod_pow(mint x, uint64_t n) { mint res = 1; while (n > 0) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } inline mint operator+(const mint &lhs, const mint &rhs) { mint res = lhs; res += rhs; return res; } inline mint operator-(const mint &lhs, const mint &rhs) { mint res = lhs; res -= rhs; return res; } inline mint operator*(const mint &lhs, const mint &rhs) { mint res = lhs; res *= rhs; return res; } inline mint operator%(const mint &lhs, const uint64_t &rhs) { return lhs; } ostream &operator<<(ostream &out, mint n) { return out << n.value; } pii dfs(const vector<pii> &G, int node, vector<bool> memo) { if (memo[node]) { return {0, 0}; } memo[node] = true; pii res = dfs(G, G[node].first, memo); res.first += 1; res.second += G[node].second; return res; } pii f(const vector<vector<pii>> &G, const vector<vector<pii>> &loop, int cur, int node, int cnt, int depth) { if (cnt == 0) { return {cur, 0}; } if (depth < 2000) { auto res = f(G, loop, G[node][cur].first, node, cnt - 1, depth + 1); res.second += G[node][cur].second; return res; } int loopcnt = cnt / loop[node][cur].first; int rest = cnt % loopcnt; cnt = rest; auto res = f(G, loop, cur, node, cnt, 0); res.second += loopcnt * loop[node][cur].second; return res; } void solve() { int M; cin >> M; vector<vector<pii>> G(10, vector<pii>(10)); vector<pii> dc(M); for (auto &a : dc) { cin >> a.first >> a.second; } REP(i, G.size()) { REP(j, G.size()) { if (i + j >= 10) { G[i][j] = {(i + j) - 9, 2}; } else { G[i][j] = {(i + j), 1}; } } } vector<vector<pii>> loop(10, vector<pii>(10)); REP(i, G.size()) { REP(j, G.size()) { vector<bool> memo(10); loop[i][j] = dfs(G[i], j, memo); } } int cur = 0; int res = 0; REP(i, M) { int d = dc[i].first; int c = dc[i].second; auto r = f(G, loop, cur, d, c, 0); cur = r.first; res += r.second; } cout << res - 1 << endl; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <ciso646> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define inf 0x3f3f3f3f3f3f3f3f #define ALL(a) (a).begin(), (a).end() #define DEBUG(x) // cerr<<#x<<": "<<x<<endl #define ll long long #define ull unsigned long long using pii = pair<ll, ll>; #define eps 1e-14 #define SETUP \ cin.tie(0), ios::sync_with_stdio(false), \ cout << setprecision(15) << std::fixed; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) template <class T> using vec2 = std::vector<vector<T>>; //// bit //// #ifdef _MSC_VER #ifdef _WIN32 inline unsigned int __builtin_ctz(unsigned int x) { unsigned long r; _BitScanForward(&r, x); return r; } inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; } inline unsigned int __builtin_ffs(unsigned int x) { unsigned long r; return _BitScanForward(&r, x) ? r + 1 : 0; } // inline unsigned int __builtin_popcount(unsigned int x){ return __popcnt(x); } #ifdef _WIN64 inline unsigned long long __builtin_ctzll(unsigned long long x) { unsigned long r; _BitScanForward64(&r, x); return r; } inline unsigned long long __builtin_clzll(unsigned long long x) { unsigned long r; _BitScanReverse64(&r, x); return 63 - r; } inline unsigned long long __builtin_ffsll(unsigned long long x) { unsigned long r; return _BitScanForward64(&r, x) ? r + 1 : 0; } inline unsigned long long __builtin_popcountll(unsigned long long x) { return __popcnt64(x); } #else inline unsigned int hidword(unsigned long long x) { return static_cast<unsigned int>(x >> 32); } inline unsigned int lodword(unsigned long long x) { return static_cast<unsigned int>(x & 0xFFFFFFFF); } inline unsigned long long __builtin_ctzll(unsigned long long x) { return lodword(x) ? __builtin_ctz(lodword(x)) : __builtin_ctz(hidword(x)) + 32; } inline unsigned long long __builtin_clzll(unsigned long long x) { return hidword(x) ? __builtin_clz(hidword(x)) : __builtin_clz(lodword(x)) + 32; } inline unsigned long long __builtin_ffsll(unsigned long long x) { return lodword(x) ? __builtin_ffs(lodword(x)) : hidword(x) ? __builtin_ffs(hidword(x)) + 32 : 0; } // inline unsigned long long __builtin_popcountll(unsigned long long x) { return // __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); } #endif // _WIN64 #endif // _WIN32 #endif // _MSC_VER namespace { struct input_returnner { ll N; input_returnner(ll N_ = 0) : N(N_) {} template <typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); } template <typename T> operator T() const { T res; cin >> res; return res; } template <typename T> T operator-(T right) { return T(input_returnner()) - right; } template <typename T> T operator+(T right) { return T(input_returnner()) + right; } template <typename T> T operator*(T right) { return T(input_returnner()) * right; } template <typename T> T operator/(T right) { return T(input_returnner()) / right; } template <typename T> T operator<<(T right) { return T(input_returnner()) << right; } template <typename T> T operator>>(T right) { return T(input_returnner()) >> right; } }; template <typename T> input_returnner in() { return in<T>(); } input_returnner in() { return input_returnner(); } input_returnner in(ll N) { return std::move(input_returnner(N)); } } // namespace template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> struct is_vector : std::false_type {}; template <typename T> struct is_vector<std::vector<T>> : std::true_type {}; template <typename T> constexpr bool is_vector_v = is_vector<T>::value; template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { for (int i = 0; i < v.size(); ++i) { out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", ")); } } return out; } namespace std { // ref: // https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set template <class T> inline void hash_combine(std::size_t &seed, T const &v) { seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } // Recursive template code derived from Matthieu M. template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1> struct HashValueImpl { static void apply(size_t &seed, Tuple const &tuple) { HashValueImpl<Tuple, Index - 1>::apply(seed, tuple); hash_combine(seed, std::get<Index>(tuple)); } }; template <class Tuple> struct HashValueImpl<Tuple, 0> { static void apply(size_t &seed, Tuple const &tuple) { hash_combine(seed, std::get<0>(tuple)); } }; template <typename... TT> struct hash<std::tuple<TT...>> { size_t operator()(std::tuple<TT...> const &tt) const { size_t seed = 0; HashValueImpl<std::tuple<TT...>>::apply(seed, tt); return seed; } }; template <class T, class U> class hash<std::pair<T, U>> { public: size_t operator()(const std::pair<T, U> &x) const { return hash<std::tuple<T, U>>()(std::tie(x.first, x.second)); } }; } // namespace std // ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple namespace aux { template <std::size_t...> struct seq {}; template <std::size_t N, std::size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, std::size_t... Is> void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using swallow = int[]; (void)swallow{0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...}; } } // namespace aux template <class Ch, class Tr, class... Args> auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t) -> std::basic_ostream<Ch, Tr> & { os << "("; aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>()); return os << ")"; } template <class S, class T> std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } // ref: // https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp template <typename T> struct reversion_wrapper { T &iterable; }; template <typename T> auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); } template <typename T> auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); } template <typename T> reversion_wrapper<T> REV(T &&iterable) { return {iterable}; } template <class T> bool inside(T left, T val, T right) { return left <= val and val < right; } template <class T> T bitCount(T num) { T res = 0; while (num > 0) { if (num & 1) ++res; num >>= 1; } return res; } ll MOD = 1e9 + 7; // ll MOD = 998244353; void solve(); signed main() { SETUP; #ifdef _DEBUG while (true) { #endif solve(); #ifdef _DEBUG cout << "-------" << endl; } #endif #ifdef _DEBUG system("pause"); #endif return 0; } #define int ll struct mint { int64_t value; mint() : value(0) {} mint(int64_t value_) : value(value_ % MOD) {} inline mint &operator+=(const mint &rhs) { value += rhs.value; if (value >= MOD) { value -= MOD; } return *this; } inline mint &operator-=(const mint &rhs) { value -= rhs.value; if (value < 0) { value += MOD; } return *this; } inline mint &operator*=(const mint &rhs) { value *= rhs.value; value %= MOD; return *this; } inline mint &operator%=(const mint &rhs) { return *this; } }; // x^n % mod // O(log n) mint mod_pow(mint x, uint64_t n) { mint res = 1; while (n > 0) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } inline mint operator+(const mint &lhs, const mint &rhs) { mint res = lhs; res += rhs; return res; } inline mint operator-(const mint &lhs, const mint &rhs) { mint res = lhs; res -= rhs; return res; } inline mint operator*(const mint &lhs, const mint &rhs) { mint res = lhs; res *= rhs; return res; } inline mint operator%(const mint &lhs, const uint64_t &rhs) { return lhs; } ostream &operator<<(ostream &out, mint n) { return out << n.value; } pii dfs(const vector<pii> &G, int node, vector<bool> memo) { if (memo[node]) { return {0, 0}; } memo[node] = true; pii res = dfs(G, G[node].first, memo); res.first += 1; res.second += G[node].second; return res; } pii f(const vector<vector<pii>> &G, const vector<vector<pii>> &loop, int cur, int node, int cnt, int depth) { if (cnt == 0) { return {cur, 0}; } if (depth < 20) { auto res = f(G, loop, G[node][cur].first, node, cnt - 1, depth + 1); res.second += G[node][cur].second; return res; } int loopcnt = cnt / loop[node][cur].first; int rest = cnt % loopcnt; cnt = rest; auto res = f(G, loop, cur, node, cnt, 0); res.second += loopcnt * loop[node][cur].second; return res; } void solve() { int M; cin >> M; vector<vector<pii>> G(10, vector<pii>(10)); vector<pii> dc(M); for (auto &a : dc) { cin >> a.first >> a.second; } REP(i, G.size()) { REP(j, G.size()) { if (i + j >= 10) { G[i][j] = {(i + j) - 9, 2}; } else { G[i][j] = {(i + j), 1}; } } } vector<vector<pii>> loop(10, vector<pii>(10)); REP(i, G.size()) { REP(j, G.size()) { vector<bool> memo(10); loop[i][j] = dfs(G[i], j, memo); } } int cur = 0; int res = 0; REP(i, M) { int d = dc[i].first; int c = dc[i].second; auto r = f(G, loop, cur, d, c, 0); cur = r.first; res += r.second; } cout << res - 1 << endl; }
replace
372
373
372
373
TLE
p02856
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mod 1000000007 using ll = long long; using namespace std; int main() { ll M; cin >> M; vector<ll> D(M); vector<ll> C(M); rep(i, M) cin >> D[i] >> C[i]; ll ans = 0; vector<ll> cntd(10, 0); rep(i, M) { if (D[i] == 0) { ans += C[i]; } else { cntd[D[i]] += C[i]; } } bool flag = true; while (flag) { vector<ll> cnt_(10, 0); rep(i, 10) { if (i == 0) continue; ans += cntd[i] / 2; } cnt_[2] += cntd[1] / 2; cnt_[1] += cntd[1] % 2; cnt_[4] += cntd[2] / 2; cnt_[2] += cntd[2] % 2; cnt_[6] += cntd[3] / 2; cnt_[3] += cntd[3] % 2; cnt_[8] += cntd[4] / 2; cnt_[4] += cntd[4] % 2; cnt_[1] += cntd[5] / 2; cnt_[0] += cntd[5] / 2; cnt_[5] += cntd[5] % 2; cnt_[1] += cntd[6] / 2; cnt_[2] += cntd[6] / 2; cnt_[6] += cntd[6] % 2; cnt_[1] += cntd[7] / 2; cnt_[4] += cntd[7] / 2; cnt_[7] += cntd[7] % 2; cnt_[1] += cntd[8] / 2; cnt_[6] += cntd[8] / 2; cnt_[8] += cntd[8] % 2; cnt_[1] += cntd[9] / 2; cnt_[8] += cntd[9] / 2; cnt_[9] += cntd[9] % 2; ans += cnt_[0]; cnt_[0] = 0; ans += 10 * (cnt_[1] / 10); cnt_[1] = cnt_[1] / 10 + cnt_[1] % 10; cntd = cnt_; rep(i, 10) { cerr << cntd[i] << " "; } cerr << endl; rep(i, 10) { if (cntd[i] >= 2) break; if (i == 9) flag = false; } // break; } cerr << "a" << endl; bool flag2 = true; vector<ll> cntt_ = cntd; while (flag2) { for (int x = 1; x < 10; x++) { for (int y = x; y < 10; y++) { if (cntt_[x] > 0 && cntt_[y] > 0) { if (x == y) { if (cntt_[x] >= 2) { if (x + y >= 10) cntt_[1]++; cntt_[(x + y) % 10]++; cntt_[x]--; cntt_[y]--; ans++; } } else { if (x + y >= 10) cntt_[1]++; cntt_[(x + y) % 10]++; cntt_[x]--; cntt_[y]--; ans++; // goto ttt; } } } } // ttt: // ans += cntt_[0]; cntt_[0] = 0; // ans += 10*(cntt_[1]/10); cntt_[1] = cntt_[1]/10+cntt_[1]%10; ll s = 0; rep(i, 10) { cerr << cntt_[i] << " "; s += cntt_[i]; } cerr << endl; if (s <= 1) flag2 = false; // ans += cnt_[0]; cnt_[0]=0; /* rep(i,10){ cntd[i] += cnt_[i]; } */ /* int cnt=0; rep(i,10){ cerr << cntd[i] << " "; cnt += cntd[i]; } cerr << endl; if(cnt==1 || cnt==0) break; */ } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mod 1000000007 using ll = long long; using namespace std; int main() { ll M; cin >> M; vector<ll> D(M); vector<ll> C(M); rep(i, M) cin >> D[i] >> C[i]; ll ans = 0; vector<ll> cntd(10, 0); rep(i, M) { if (D[i] == 0) { ans += C[i]; } else { cntd[D[i]] += C[i]; } } bool flag = true; while (flag) { vector<ll> cnt_(10, 0); rep(i, 10) { if (i == 0) continue; ans += cntd[i] / 2; } cnt_[2] += cntd[1] / 2; cnt_[1] += cntd[1] % 2; cnt_[4] += cntd[2] / 2; cnt_[2] += cntd[2] % 2; cnt_[6] += cntd[3] / 2; cnt_[3] += cntd[3] % 2; cnt_[8] += cntd[4] / 2; cnt_[4] += cntd[4] % 2; cnt_[1] += cntd[5] / 2; cnt_[0] += cntd[5] / 2; cnt_[5] += cntd[5] % 2; cnt_[1] += cntd[6] / 2; cnt_[2] += cntd[6] / 2; cnt_[6] += cntd[6] % 2; cnt_[1] += cntd[7] / 2; cnt_[4] += cntd[7] / 2; cnt_[7] += cntd[7] % 2; cnt_[1] += cntd[8] / 2; cnt_[6] += cntd[8] / 2; cnt_[8] += cntd[8] % 2; cnt_[1] += cntd[9] / 2; cnt_[8] += cntd[9] / 2; cnt_[9] += cntd[9] % 2; ans += cnt_[0]; cnt_[0] = 0; ans += 10 * (cnt_[1] / 10); cnt_[1] = cnt_[1] / 10 + cnt_[1] % 10; cntd = cnt_; rep(i, 10) { cerr << cntd[i] << " "; } cerr << endl; rep(i, 10) { if (cntd[i] >= 2) break; if (i == 9) flag = false; } // break; } cerr << "a" << endl; bool flag2 = true; vector<ll> cntt_ = cntd; while (flag2) { for (int x = 0; x < 10; x++) { for (int y = x; y < 10; y++) { if (cntt_[x] > 0 && cntt_[y] > 0) { if (x == y) { if (cntt_[x] >= 2) { if (x + y >= 10) cntt_[1]++; cntt_[(x + y) % 10]++; cntt_[x]--; cntt_[y]--; ans++; } } else { if (x + y >= 10) cntt_[1]++; cntt_[(x + y) % 10]++; cntt_[x]--; cntt_[y]--; ans++; // goto ttt; } } } } // ttt: // ans += cntt_[0]; cntt_[0] = 0; // ans += 10*(cntt_[1]/10); cntt_[1] = cntt_[1]/10+cntt_[1]%10; ll s = 0; rep(i, 10) { cerr << cntt_[i] << " "; s += cntt_[i]; } cerr << endl; if (s <= 1) flag2 = false; // ans += cnt_[0]; cnt_[0]=0; /* rep(i,10){ cntd[i] += cnt_[i]; } */ /* int cnt=0; rep(i,10){ cerr << cntd[i] << " "; cnt += cntd[i]; } cerr << endl; if(cnt==1 || cnt==0) break; */ } cout << ans << endl; return 0; }
replace
86
87
86
87
TLE
p02856
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; #define fi first #define se second #define mp make_pair #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = (int)1e5 + 9; ll d[N], c[N]; int main() { fastIO; int n; cin >> n; ll len = 0, sum = 0; for (int i = 1; i <= n; i++) { cin >> d[i] >> c[i]; sum += d[i] * c[i]; len += c[i]; } ll ans = len - 1; if (sum >= 9) ans += (sum - 1) / 9; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; #define fi first #define se second #define mp make_pair #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = (int)2e5 + 9; ll d[N], c[N]; int main() { fastIO; int n; cin >> n; ll len = 0, sum = 0; for (int i = 1; i <= n; i++) { cin >> d[i] >> c[i]; sum += d[i] * c[i]; len += c[i]; } ll ans = len - 1; if (sum >= 9) ans += (sum - 1) / 9; cout << ans << "\n"; return 0; }
replace
17
18
17
18
0
p02856
C++
Time Limit Exceeded
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i, a, b) for (ll i = (a); i < (b); ++i) #define per(i, a, b) for (ll i = b - 1LL; i >= (a); --i) #define clr(a, b) memset((a), (b), sizeof(a)) #define ctos(c) string(1, c) #define print(x) cout << #x << " = " << x << endl; #define MOD 10 int main() { ll m; cin >> m; ll a = 0; ll ans = 0; rep(i, 0, m) { ll d, c; cin >> d >> c; a += d * c; ans += c; } ans--; while (a > 9) { ll b = a / 10; ans += b; a += b; } cout << ans << endl; return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i, a, b) for (ll i = (a); i < (b); ++i) #define per(i, a, b) for (ll i = b - 1LL; i >= (a); --i) #define clr(a, b) memset((a), (b), sizeof(a)) #define ctos(c) string(1, c) #define print(x) cout << #x << " = " << x << endl; #define MOD 10 int main() { ll m; cin >> m; ll a = 0; ll ans = 0; rep(i, 0, m) { ll d, c; cin >> d >> c; a += d * c; ans += c; } ans--; while (a > 9) { ll b = a / 10; ans += b; a %= 10; a += b; } cout << ans << endl; return 0; }
insert
53
53
53
54
TLE
p02856
C++
Runtime Error
#include <cstdio> int m, d; long long len, sum, c; int main() { scanf("%d", &m); len = sum = -1; for (int i = 0; i < m; ++i) { scanf("%d%lld", d, c); len += c; sum += c * d; } printf("%lld\n", len + sum / 9); }
#include <cstdio> int m, d; long long len, sum, c; int main() { scanf("%d", &m); len = sum = -1; for (int i = 0; i < m; ++i) { scanf("%d%lld", &d, &c); len += c; sum += c * d; } printf("%lld\n", len + sum / 9); }
replace
8
9
8
9
-11
p02858
Python
Runtime Error
from math import gcd mod = 10**9 + 7 n, m, t = map(int, input().split()) a = gcd(n, t) b = gcd(m, t) n //= a m //= b ret = pow(2, n, mod) + pow(2, m, mod) + pow(2, gcd(n, m), mod) - 3 print(pow(ret, a * b, mod))
from fractions import gcd mod = 10**9 + 7 n, m, t = map(int, input().split()) a = gcd(n, t) b = gcd(m, t) n //= a m //= b ret = pow(2, n, mod) + pow(2, m, mod) + pow(2, gcd(n, m), mod) - 3 print(pow(ret, a * b, mod))
replace
0
1
0
1
0
p02858
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; template <typename T> T gcd(T a, T b) { if (a < b) swap(a, b); while (b != 0) { T tmp = b; b = a % b; a = tmp; } return a; } template <typename T> T lcm(T a, T b) { return (a * b) / gcd<T>(a, b); } template <typename T> T pow(T a, ll n) { T ans = 1; T tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll H, W, T; cin >> H >> W >> T; ll h, w; h = lcm<ll>(H, T) / T; w = lcm<ll>(W, T) / T; ll ans = 0; if (gcd<ll>(h, w) != 1) return -1; ans += pow<ll>(2, h); ans %= MOD; ans += pow<ll>(2, w); ans--; ans %= MOD; ans = pow<ll>(ans, H * W / (h * w)); cout << ans << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; template <typename T> T gcd(T a, T b) { if (a < b) swap(a, b); while (b != 0) { T tmp = b; b = a % b; a = tmp; } return a; } template <typename T> T lcm(T a, T b) { return (a * b) / gcd<T>(a, b); } template <typename T> T pow(T a, ll n) { T ans = 1; T tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll H, W, T; cin >> H >> W >> T; ll h, w; h = lcm<ll>(H, T) / T; w = lcm<ll>(W, T) / T; ll ans = 0; if (gcd<ll>(h, w) != 1) { ll p = h * w / lcm<ll>(h, w); ans += (pow<ll>(2, p) - 2); ans %= MOD; // ans += (pow<ll>(2, p)-2); // ans %= MOD; } ans += pow<ll>(2, h); ans %= MOD; ans += pow<ll>(2, w); ans--; ans %= MOD; ans = pow<ll>(ans, H * W / (h * w)); cout << ans << endl; }
replace
50
52
50
57
255
p02859
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; using namespace std; #define mod 1000000007 int n, a, b, k, h, m, c; int main() { scanf("%d", a); printf("%d", a * a); return 0; }
#include <bits/stdc++.h> typedef long long int ll; using namespace std; #define mod 1000000007 int n, a, b, k, h, m, c; int main() { cin >> a; cout << a * a; return 0; }
replace
7
9
7
9
-11
p02859
C++
Runtime Error
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #define ll long long #define l long #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pii pair<int, int> #define maxn 100005 using namespace std; signed main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll r; cin >> r; cout << r * r; }
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #define ll long long #define l long #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pii pair<int, int> #define maxn 100005 using namespace std; signed main() { fast; ll r; cin >> r; cout << r * r; }
replace
40
44
40
41
0
p02859
C++
Runtime Error
// AUTHOR: *Akash Shrivastva* // Birla Institute of Technology,Mesra,India #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define M 1000000007 #define mp make_pair #define pb push_back #define vll vector<ll> #define pll vector<pair<ll, ll>> #define F first #define S second #define PII pair<ll, ll> int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll r; cin >> r; cout << r * r << endl; }
// AUTHOR: *Akash Shrivastva* // Birla Institute of Technology,Mesra,India #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define M 1000000007 #define mp make_pair #define pb push_back #define vll vector<ll> #define pll vector<pair<ll, ll>> #define F first #define S second #define PII pair<ll, ll> int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll r; cin >> r; cout << r * r << endl; }
delete
19
23
19
19
0
p02859
C++
Time Limit Exceeded
#include <algorithm> #include <array> #include <bitset> #include <cstdlib> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <type_traits> #include <utility> #include <vector> using namespace std; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const double PI = acos(-1.0); #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define all(v) v.begin(), v.end() inline void finish() { cout << -1 << endl; exit(0); } template <typename T> inline void debug(vector<T> v) { cout << "["; for (ll i = 0; i < v.size() - 1; ++i) { cout << v[i] << ", "; } cout << v[v.size() - 1] << "]" << endl; } void Main(); inline void DebugMain() { while (true) { Main(); } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); bool debug = true; if (debug) { cout << "\x1b[41m" << "Debug Mode " << endl; } (debug) ? DebugMain() : Main(); return 0; } inline void Main() { int r; cin >> r; cout << r * r; }
#include <algorithm> #include <array> #include <bitset> #include <cstdlib> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <type_traits> #include <utility> #include <vector> using namespace std; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const double PI = acos(-1.0); #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define all(v) v.begin(), v.end() inline void finish() { cout << -1 << endl; exit(0); } template <typename T> inline void debug(vector<T> v) { cout << "["; for (ll i = 0; i < v.size() - 1; ++i) { cout << v[i] << ", "; } cout << v[v.size() - 1] << "]" << endl; } void Main(); inline void DebugMain() { while (true) { Main(); } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); bool debug = false; if (debug) { cout << "\x1b[41m" << "Debug Mode " << endl; } (debug) ? DebugMain() : Main(); return 0; } inline void Main() { int r; cin >> r; cout << r * r; }
replace
55
56
55
56
TLE
p02859
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int r; cin >> r; while (1) { } cout << r; return 0; }
#include <iostream> using namespace std; int main() { int r; cin >> r; cout << r * r; return 0; }
replace
7
10
7
9
TLE
p02859
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int r; cin >> r; return r * r; }
#include <bits/stdc++.h> using namespace std; int main() { int r; cin >> r; cout << r * r; }
replace
6
7
6
7
4
p02859
C++
Runtime Error
// // main.cpp // ABC124 // // Created by hiroaki on 2019/05/07. // Copyright © 2019年 hiroaki. All rights reserved. // #include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <tuple> #include <vector> // pair sort firstに揃う #define int long long #define double long double #define Rap(n, i) for (int(i) = 0; (i) < (n); (i)++) #define Pr(n) cout << n << endl; #define PairV vector<pair<int, int>> #define F first #define S second #define Vector1 vector<int> #define VectorS vector<string> #define vector2 vector<vector<int>> #define index(v, x) find((v).begin(), (v).end(), (x)) - (v).begin() #define ctoi(c) (int)(c - '0') #define incin(n) \ int(n); \ cin >> (n); #define incin2(n, m) \ int(n), (m); \ cin >> (n) >> (m); #define stcin(s) \ string(s); \ cin >> (s); #define all(v) (v).begin(), (v).end() namespace Mathf { const int INF = 1000000000000; const double PI = 3.14159274; const double Rad2Deg = 57.29578; const double log2(double a, double b); const double log2(double a, double b) { return log(b) / log(a); } } // namespace Mathf using namespace std; int MD(pair<int, int> a, pair<int, int> b) { // ManhattanDisRance return abs(a.first - b.first) + abs(a.second - b.second); } int MOD(int a, int b) { return abs(a % b); } template <typename T1, typename T2> bool Comp(pair<T1, T2> a, pair<T1, T2> b) { if (a.first != b.first) { return a.first < b.first; // first昇順 } if (a.second != b.second) { return a.second > b.second; // second降順 } else { return true; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); incin2(h, w); vector<int> b(w); vector<vector<int>> a(h, b); incin(r); Pr(r * r); return 0; }
// // main.cpp // ABC124 // // Created by hiroaki on 2019/05/07. // Copyright © 2019年 hiroaki. All rights reserved. // #include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <tuple> #include <vector> // pair sort firstに揃う #define int long long #define double long double #define Rap(n, i) for (int(i) = 0; (i) < (n); (i)++) #define Pr(n) cout << n << endl; #define PairV vector<pair<int, int>> #define F first #define S second #define Vector1 vector<int> #define VectorS vector<string> #define vector2 vector<vector<int>> #define index(v, x) find((v).begin(), (v).end(), (x)) - (v).begin() #define ctoi(c) (int)(c - '0') #define incin(n) \ int(n); \ cin >> (n); #define incin2(n, m) \ int(n), (m); \ cin >> (n) >> (m); #define stcin(s) \ string(s); \ cin >> (s); #define all(v) (v).begin(), (v).end() namespace Mathf { const int INF = 1000000000000; const double PI = 3.14159274; const double Rad2Deg = 57.29578; const double log2(double a, double b); const double log2(double a, double b) { return log(b) / log(a); } } // namespace Mathf using namespace std; int MD(pair<int, int> a, pair<int, int> b) { // ManhattanDisRance return abs(a.first - b.first) + abs(a.second - b.second); } int MOD(int a, int b) { return abs(a % b); } template <typename T1, typename T2> bool Comp(pair<T1, T2> a, pair<T1, T2> b) { if (a.first != b.first) { return a.first < b.first; // first昇順 } if (a.second != b.second) { return a.second > b.second; // second降順 } else { return true; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); incin(r); Pr(r * r); return 0; }
delete
65
69
65
65
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02859
Python
Runtime Error
r = input() print(r**2)
r = int(input()) print(r**2)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s029967199.py", line 2, in <module> print(r ** 2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02859
Python
Runtime Error
N = input() print(N**2)
N = int(input()) print(N**2)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s490869549.py", line 2, in <module> print(N**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02859
Python
Runtime Error
r = int(input) print(int(r**2))
r = int(input()) print(int(r**2))
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s021145542.py", line 1, in <module> r = int(input) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
p02859
Python
Runtime Error
r = input() ans = r * r print(ans)
r = int(input()) ans = r * r print(ans)
replace
0
1
0
1
TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s972374104.py", line 2, in <module> ans = r * r TypeError: can't multiply sequence by non-int of type 'str'
p02859
Python
Runtime Error
r = int(input) print(r**2)
r = int(input()) print(r**2)
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s774524260.py", line 1, in <module> r = int(input) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
p02859
Python
Runtime Error
r = int(input().split()) print(r * r)
r = int(input().strip()) print(r * r)
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s880229188.py", line 1, in <module> r = int(input().split()) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
p02859
Python
Runtime Error
from sys import stdin r = stdin.readline().rstrip() print(r**2)
from sys import stdin r = int(stdin.readline().rstrip()) print(r**2)
replace
2
3
2
3
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s930082773.py", line 5, in <module> print(r ** 2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02859
Python
Runtime Error
r = int(input) x = r**2 print(x)
r = int(input()) x = r**2 print(x)
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s925177470.py", line 1, in <module> r = int(input) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
p02859
Python
Runtime Error
print(int(input() ** 2))
print(int(input()) ** 2)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s090914848.py", line 1, in <module> print(int(input()**2)) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02859
Python
Runtime Error
r = input() print(r**2)
r = int(input()) print(r**2)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s447174511.py", line 2, in <module> print(r**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02859
Python
Runtime Error
import sys r = sys.argv[1] print(int(r) ** 2)
r = input() print(int(r) ** 2)
replace
0
3
0
1
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02859/Python/s456514871.py", line 2, in <module> r = sys.argv[1] IndexError: list index out of range
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; if (n % 2 == 1) { cout << "No" << endl; } else { for (int i = 0; i < n / 2; i++) { if (s.at(i) != s.at(n / 2 + i)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; if (n % 2 == 1) { cout << "No" << endl; } else { for (int i = 0; i < n / 2; i++) { if (s.at(i) != s.at(n / 2 + i)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } }
insert
8
8
8
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; int t = S.size(); if (t % 2 != 0) cout << "No" << endl; else { vector<char> T(t); for (int i = 0; i < t / 2; i++) { T.at(i) = S.at(i); T.at(i + 3) = S.at(i); } int c = 0; for (int i = 0; i < t; i++) { if (T.at(i) != S.at(i)) c = 1; } if (c == 0) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; int t = S.size(); if (t % 2 != 0) cout << "No" << endl; else { vector<char> T(t); for (int i = 0; i < t / 2; i++) { T.at(i) = S.at(i); T.at(i + t / 2) = S.at(i); } int c = 0; for (int i = 0; i < t; i++) { if (T.at(i) != S.at(i)) c = 1; } if (c == 0) cout << "Yes" << endl; else cout << "No" << endl; } }
replace
13
14
13
14
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; return 1; } bool flag = true; for (long long i = 0; i < n / 2; i++) { if (s[i] != s[i + n / 2]) flag = false; } if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; return 0; } bool flag = true; for (long long i = 0; i < n / 2; i++) { if (s[i] != s[i + n / 2]) flag = false; } if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
10
11
10
11
0
p02860
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long using namespace std; struct all_init { all_init() { cout << fixed << setprecision(12); } } All_init; int main() { ll n; cin >> n; string s; if (n % 2 != 0) { cout << "No" << endl; exit(0); } string sa = s.substr(0, n / 2); string sb = s.substr(n / 2, n / 2); if (sa == sb) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long using namespace std; struct all_init { all_init() { cout << fixed << setprecision(12); } } All_init; int main() { ll n; cin >> n; string s; cin >> s; if (n % 2 != 0) { cout << "No" << endl; exit(0); } string sa = s.substr(0, n / 2); string sb = s.substr(n / 2, n / 2); if (sa == sb) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
insert
22
22
22
23
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 3) > this->size() (which is 0)
p02860
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long ll; using namespace std; int main(void) { int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; return 0; } string t0 = s.substr(0, 3), t1 = s.substr(3, 3); if (t0 == t1) { cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long ll; using namespace std; int main(void) { int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; return 0; } n >>= 1; string t0 = s.substr(0, n), t1 = s.substr(n, n); if (t0 == t1) { cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
replace
15
16
15
17
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; } else { vector<char> hoge1(n / 2); vector<char> hoge2(n / 2); for (int i = 0; i < n; i++) { if (i <= n / 2 - 1) hoge1.at(i) = s.at(i); else hoge2.at(i - 3) = s.at(i); } if (hoge1 == hoge2) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No" << endl; } else { vector<char> hoge1(n / 2); vector<char> hoge2(n / 2); for (int i = 0; i < n; i++) { if (i <= n / 2 - 1) hoge1.at(i) = s.at(i); else hoge2.at(i - n / 2) = s.at(i); } if (hoge1 == hoge2) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
replace
17
18
17
18
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { freopen("test.in", "r", stdin); int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No"; return 0; } string a = ""; for (int k = 0; k < n / 2; k++) a += s[k]; a = a + a; if (a == s) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // freopen("test.in","r",stdin); int n; string s; cin >> n >> s; if (n % 2 == 1) { cout << "No"; return 0; } string a = ""; for (int k = 0; k < n / 2; k++) a += s[k]; a = a + a; if (a == s) cout << "Yes"; else cout << "No"; return 0; }
replace
4
5
4
5
-11
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; bool flag = true; // Nが奇数のときは必ず'NO' if (N % 2 == 1) flag = false; else { for (int i = 0; i < S.size(); i++) { if (S.at(i) != S.at(i + N / 2)) { flag = false; break; } } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; bool flag = true; // Nが奇数のときは必ず'NO' if (N % 2 == 1) flag = false; else { for (int i = 0; i < N / 2; i++) { if (S.at(i) != S.at(i + N / 2)) { flag = false; break; } } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
p02860
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> using namespace std; string alphabet = "abcdefghijklmnopqrstuvwxyz"; string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int n; cin >> n; n = 6; string s; cin >> s; if (n % 2 == 0) { int t = n / 2; string k = s.substr(0, t); string l = s.substr(t, t); if (k == l) cout << "Yes" << endl; else cout << "No" << endl; } else cout << "No" << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> using namespace std; string alphabet = "abcdefghijklmnopqrstuvwxyz"; string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int n; cin >> n; string s; cin >> s; if (n % 2 == 0) { int t = n / 2; string k = s.substr(0, t); string l = s.substr(t, t); if (k == l) cout << "Yes" << endl; else cout << "No" << endl; } else cout << "No" << endl; }
delete
11
12
11
11
0
p02860
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; string s; cin >> N; cin >> s; int n; n = N / 2; int i = 0; if (N % 2 == 1) { cout << "No"; } else { int b = 1; while (i < n) { if (s.at(i) != s.at(i + n)) { b = 0; } } if (b == 1) { cout << "Yes"; } else { cout << "No"; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N; string s; cin >> N; cin >> s; int n; n = N / 2; int i = 0; if (N % 2 == 1) { cout << "No"; } else { int b = 1; for (int i; i < n; i++) { if (s.at(i) != s.at(i + n)) { b = 0; } } if (b == 1) { cout << "Yes"; } else { cout << "No"; } } }
replace
18
19
18
19
TLE
p02860
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; if (n % 2 != 0) { cout << "No" << endl; return -1; } string s; cin >> s; const int m = n / 2; string p1 = s.substr(0, m); string p2 = s.substr(m, m); if (p1 == p2) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; if (n % 2 != 0) { cout << "No" << endl; return 0; } string s; cin >> s; const int m = n / 2; string p1 = s.substr(0, m); string p2 = s.substr(m, m); if (p1 == p2) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
10
11
10
11
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; if (N % 2 == 1) { cout << "No" << endl; return 0; } string s1; s1 = S.substr(3); S = S.erase(3); if (s1 == S) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; if (N % 2 == 1) { cout << "No" << endl; return 0; } string s1; s1 = S.substr(N / 2); S = S.erase(N / 2); if (s1 == S) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
16
18
16
18
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; string ans = "Yes"; if (S.size() % 2 != 0) { ans = "No"; } for (int i = 0; i < N; i++) { if (S.at(i) != S.at(N / 2 + i)) { ans = "No"; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; string ans = "Yes"; if (S.size() % 2 != 0) { ans = "No"; } for (int i = 0; i < N / 2; i++) { if (S.at(i) != S.at(N / 2 + i)) { ans = "No"; break; } } cout << ans << endl; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string s; scanf("%d", &n); cin >> s; if (n % 2 != 0) { cout << "No" << "\n"; } else { if (s.substr(0, n / 2) == s.substr(n / 2, string::npos)) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string s; cin >> n >> s; if (n % 2 != 0) { cout << "No" << "\n"; } else { if (s.substr(0, n / 2) == s.substr(n / 2, string::npos)) cout << "Yes\n"; else cout << "No\n"; } return 0; }
replace
8
10
8
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 3) > this->size() (which is 0)
p02860
C++
Runtime Error
#include <iostream> using namespace std; const string YES = "Yes"; const string NO = "No"; void solve(long long N, std::string S) { if (N % 2) cout << NO << '\n'; else { string s1 = S.substr(0, N / 2); string s2 = S.substr(N / 2); if (s1 == s2) cout << YES << '\n'; else cout << NO << '\n'; } } int main() { cin.tie(0); ios::sync_with_stdio(false); long long N; scanf("%lld", &N); std::string S; std::cin >> S; solve(N, S); return 0; }
#include <iostream> using namespace std; const string YES = "Yes"; const string NO = "No"; void solve(long long N, std::string S) { if (N % 2) cout << NO << '\n'; else { string s1 = S.substr(0, N / 2); string s2 = S.substr(N / 2); if (s1 == s2) cout << YES << '\n'; else cout << NO << '\n'; } } int main() { cin.tie(0); ios::sync_with_stdio(false); long long N; cin >> N; std::string S; std::cin >> S; solve(N, S); return 0; }
replace
23
24
23
24
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 3) > this->size() (which is 0)
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int r; string s; cin >> r; cin >> s; if (r % 2 != 0) { printf("No"); } else { if (s.substr(0, 3) == (s.substr(3, 6))) { printf("Yes"); } else printf("No"); } }
#include <bits/stdc++.h> using namespace std; int main() { int r; string s; cin >> r; cin >> s; if (r % 2 != 0) { printf("No"); } else { if (s.substr(0, r / 2) == (s.substr(r / 2, r))) { printf("Yes"); } else printf("No"); } }
replace
10
11
10
11
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; string tmp; cin >> n >> tmp; vector<string> str(n); for (int i = 0; i < n; ++i) str.at(i) = tmp[i]; sort(str.begin(), str.end()); if (n < 2) { cout << "No"; return 0; } for (int i = 0; i < n; i = i + 2) { if (str[i] != str[i + 1]) { cout << "No"; return 0; } } cout << "Yes"; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string tmp; cin >> n >> tmp; vector<string> str(n); for (int i = 0; i < n; ++i) str.at(i) = tmp[i]; sort(str.begin(), str.end()); if (n % 2 == 1) { cout << "No"; return 0; } for (int i = 0; i < n; i = i + 2) { if (str[i] != str[i + 1]) { cout << "No"; return 0; } } cout << "Yes"; }
replace
14
15
14
15
0
p02860
Python
Runtime Error
def solve(string): n, s = string.split() n = int(n) return "Yes" if s[: n // 2] == s[n // 2 :] else "No" if __name__ == "__main__": print(solve(input()))
def solve(string): n, s = string.split() n = int(n) return "Yes" if s[: n // 2] == s[n // 2 :] else "No" if __name__ == "__main__": print(solve("\n".join([input(), input()])))
replace
7
8
7
8
ValueError: not enough values to unpack (expected 2, got 1)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02860/Python/s478771892.py", line 8, in <module> print(solve(input())) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02860/Python/s478771892.py", line 2, in solve n, s = string.split() ValueError: not enough values to unpack (expected 2, got 1)
p02860
Python
Runtime Error
N = int(input()) S = int(input()) if N % 2 != 0: print("No") else: arr = list(S) s_len = len(arr) // 2 if arr[s_len:] == arr[:s_len]: print("Yes") else: print("No")
N = int(input()) S = input() if N % 2 != 0: print("No") else: arr = list(S) s_len = len(arr) // 2 if arr[s_len:] == arr[:s_len]: print("Yes") else: print("No")
replace
1
2
1
2
ValueError: invalid literal for int() with base 10: 'abcabc'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02860/Python/s186953339.py", line 2, in <module> S = int(input()) ValueError: invalid literal for int() with base 10: 'abcabc'
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { string s; int n; cin >> n, s; bool ans = true; if (n % 2 == 1) ans = false; else { rep(i, n / 2) { if (s.at(i) != s.at(i + n / 2)) ans = false; } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { string s; int n; cin >> n >> s; bool ans = true; if (n % 2 == 1) ans = false; else { rep(i, n / 2) { if (s.at(i) != s.at(i + n / 2)) ans = false; } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
replace
6
7
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; int i; cin >> N; cin >> S; int a; a = N / 2; if (N % 2 == 1) { cout << "No" << endl; return 0; } else { for (i == 0; i < N; i++) { if (S.at(i) == S.at(i + a)) { } else { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; int i; cin >> N; cin >> S; int a; a = N / 2; if (N % 2 == 1) { cout << "No" << endl; return 0; } else { for (i == 0; i < a; i++) { if (S.at(i) == S.at(i + a)) { } else { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } }
replace
16
17
16
17
0
p02860
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n; string s; cin >> n; cin >> s; // n = 10; // s = "aabbcaabbc"; if (n % 2 == 1) { printf("No"); return 0; } const char *ss = s.c_str(); for (int i = 0; i < n / 2; i++) { if (ss[i] != ss[i + n / 2]) { printf("No"); return 0; } } return printf("Yes"); }
#include <iostream> using namespace std; int main() { int n; string s; cin >> n; cin >> s; // n = 10; // s = "aabbcaabbc"; if (n % 2 == 1) { printf("No"); return 0; } const char *ss = s.c_str(); for (int i = 0; i < n / 2; i++) { if (ss[i] != ss[i + n / 2]) { printf("No"); return 0; } } printf("Yes"); return 0; }
replace
26
27
26
28
3
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; bool nazo = true; for (int i = 0; i < S.size() / 2; i++) { if (S.at(i) == S.at(i + 3)) { nazo = true; } else { nazo = false; break; } } if (N == 1) { nazo = false; } if (nazo) { cout << "Yes"; } else { cout << "No"; } }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; bool nazo = true; if (N % 2 == 0 && S.substr(0, N / 2) == S.substr(N / 2, N)) { nazo = true; } else { nazo = false; } if (N == 1) { nazo = false; } if (nazo) { cout << "Yes"; } else { cout << "No"; } }
replace
7
15
7
11
0
p02860
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N; string S; cin >> N >> S; if (N % 2 == 0) { int center = N / 2; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(i + center)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
#include <iostream> using namespace std; int main() { int N; string S; cin >> N >> S; if (N % 2 == 0) { int center = N / 2; for (int i = 0; i < center; i++) { if (S.at(i) != S.at(i + center)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
p02860
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define prin(a) cout << (a) << endl using ll = int64_t; using namespace std; // define gcd and lcm (using 64bit) ll gcd(ll a, ll b) { if (a < b) { //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。 a ^= b; b ^= a; a ^= b; } // only when b==0,this program finds that b means false and returns a. return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main() { int n; string s; cin >> n >> s; bool ok = true; if (n % 2 == 1) { ok = false; } else { string t, u; t = s.substr(0, (n / 2)); u = s.substr(3, (n / 2)); if (t != u) ok = false; } cout << (ok ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define prin(a) cout << (a) << endl using ll = int64_t; using namespace std; // define gcd and lcm (using 64bit) ll gcd(ll a, ll b) { if (a < b) { //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。 a ^= b; b ^= a; a ^= b; } // only when b==0,this program finds that b means false and returns a. return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main() { int n; string s; cin >> n >> s; bool ok = true; if (n % 2 == 1) { ok = false; } else { string t, u; t = s.substr(0, (n / 2)); u = s.substr((n / 2), (n / 2)); if (t != u) ok = false; } cout << (ok ? "Yes" : "No") << endl; return 0; }
replace
30
31
30
31
0
p02860
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; int main() { int N; string S; cin >> N; cin >> S; int cnt = 0; if (N % 2 != 0) { cout << "No" << endl; } else { rep(i, N) { if (S.at(i) == S.at(i + (N / 2))) cnt++; } if (cnt == N / 2) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; int main() { int N; string S; cin >> N; cin >> S; int cnt = 0; if (N % 2 != 0) { cout << "No" << endl; } else { rep(i, N / 2) { if (S.at(i) == S.at(i + (N / 2))) cnt++; } if (cnt == N / 2) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
replace
16
17
16
17
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
p02860
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string S; getline(cin, S); if (n % 2 == 0 && (S.substr(0, n / 2) == S.substr(n / 2, n))) { cout << "Yes"; } else { cout << "No"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string S; cin >> S; if (n % 2 == 0 && (S.substr(0, n / 2) == S.substr(n / 2, n))) { cout << "Yes"; } else { cout << "No"; } }
replace
9
10
9
10
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 3) > this->size() (which is 0)
p02860
Python
Runtime Error
n = int(input()) s = input() ans = "No" if n % 2 == 0: ans = "Yes" for i in range(n / 2): if s[i] != s[n / 2 + i]: ans = "No" break print(ans)
n = int(input()) s = input() ans = "No" if n % 2 == 0: ans = "Yes" for i in range(n // 2): if s[i] != s[n // 2 + i]: ans = "No" break print(ans)
replace
5
7
5
7
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02860/Python/s022164402.py", line 6, in <module> for i in range(n / 2): TypeError: 'float' object cannot be interpreted as an integer
p02861
Python
Runtime Error
import sys from itertools import permutations from math import factorial read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def distance2(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def main(): N = int(readline()) C = [tuple(map(int, readline().split())) for _ in range(N)] dist = [[0] * N for _ in range(N)] for i in range(N): for j in range(i + 1, N): dist[i][j] = dist[j][i] = distance2(*C[i], *C[j]) ans = 0 for perm in permutations(range(N)): for i in range(N - 1): ans += dist[perm[i]][perm[i + 1]] print(ans / factorial(N)) return if __name__ == "__main__": main()
import sys from itertools import permutations from math import factorial read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def distance2(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def main(): N = int(readline()) C = [tuple(map(int, readline().split())) for _ in range(N)] dist = [[0] * N for _ in range(N)] for i in range(N): for j in range(i + 1, N): dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1]) ans = 0 for perm in permutations(range(N)): for i in range(N - 1): ans += dist[perm[i]][perm[i + 1]] print(ans / factorial(N)) return if __name__ == "__main__": main()
replace
22
23
22
23
0