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
p03014
C++
Runtime Error
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) x.begin(), x.end() using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("\n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } const int mod = 1e9 + 7; const int maxWH = 2005; array<array<int, maxWH>, maxWH> grid; signed main() { int h, w; std::cin >> h >> w; REP(i, w + 2) { grid[0][i] = 1, grid[h + 1][i] = 1; } REP(i, h + 2) { grid[i][0] = 1, grid[i][w + 1] = 1; } FOR(y, 1, h + 1) { string s = readString(); int x = 1; for (auto &c : s) { if (c == '#') grid[y][x++] = 1; else grid[y][x++] = 0; } } auto cntVertical = [](int y, int x) { int ret = 0; for (int i = y - 1; grid[i][x] == 0; i--) ret++; for (int i = y + 1; grid[i][x] == 0; i++) ret++; return ret; }; auto cntHorizontal = [](int y, int x) { int ret = 0; for (int i = x - 1; grid[y][i] == 0; i--) ret++; for (int i = x + 1; grid[y][i] == 0; i++) ret++; return ret; }; int ans = 0; int horCnt[w + 1], verCnt[h + 1]; FOR(y, 1, h + 1) FOR(x, 1, w + 1) { if (grid[y][x] == 1) continue; int tmp = 1; // vertical if (grid[y - 1][x] == 1) verCnt[x] = cntVertical(y, x); tmp += verCnt[x]; // horizontal if (grid[y][x - 1] == 1) horCnt[y] = cntHorizontal(y, x); tmp += horCnt[y]; chmax(ans, tmp); } print(ans); }
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) x.begin(), x.end() using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("\n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } const int mod = 1e9 + 7; const int maxWH = 2005; array<array<int, maxWH>, maxWH> grid; signed main() { int h, w; std::cin >> h >> w; REP(i, w + 2) { grid[0][i] = 1, grid[h + 1][i] = 1; } REP(i, h + 2) { grid[i][0] = 1, grid[i][w + 1] = 1; } FOR(y, 1, h + 1) { string s = readString(); int x = 1; for (auto &c : s) { if (c == '#') grid[y][x++] = 1; else grid[y][x++] = 0; } } auto cntVertical = [](int y, int x) { int ret = 0; for (int i = y - 1; grid[i][x] == 0; i--) ret++; for (int i = y + 1; grid[i][x] == 0; i++) ret++; return ret; }; auto cntHorizontal = [](int y, int x) { int ret = 0; for (int i = x - 1; grid[y][i] == 0; i--) ret++; for (int i = x + 1; grid[y][i] == 0; i++) ret++; return ret; }; int ans = 0; int horCnt[h + 1], verCnt[w + 1]; FOR(y, 1, h + 1) FOR(x, 1, w + 1) { if (grid[y][x] == 1) continue; int tmp = 1; // vertical if (grid[y - 1][x] == 1) verCnt[x] = cntVertical(y, x); tmp += verCnt[x]; // horizontal if (grid[y][x - 1] == 1) horCnt[y] = cntHorizontal(y, x); tmp += horCnt[y]; chmax(ans, tmp); } print(ans); }
replace
117
118
117
118
0
p03014
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; ++i) cin >> s[i]; vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; ++i) { vector<int> done(w); for (int j = 0; j < w; ++j) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < w) { if (s[i][j + l] == '#') break; ++l; } for (int k = 0; k < l; ++k) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < h; ++j) { vector<int> done(h); for (int i = 0; i < h; ++i) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; ++l; } for (int k = 0; k < l; ++k) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) ans = max(ans, cnt[i][j] - 1); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; ++i) cin >> s[i]; vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; ++i) { vector<int> done(w); for (int j = 0; j < w; ++j) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < w) { if (s[i][j + l] == '#') break; ++l; } for (int k = 0; k < l; ++k) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < w; ++j) { vector<int> done(h); for (int i = 0; i < h; ++i) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; ++l; } for (int k = 0; k < l; ++k) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) ans = max(ans, cnt[i][j] - 1); cout << ans << endl; return 0; }
replace
36
37
36
37
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int preC[maxn][maxn], preR[maxn][maxn]; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) { cin >> a[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] != '#') preR[i][j + 1] = preR[i][j] + 1; } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (a[j][i] != '#') { preC[j + 1][i] = preC[j][i] + 1; } } } for (int i = 0; i < h; i++) { for (int j = w; j > 1; j--) { if (preR[i][j] != 0) { if (a[i][j - 2] != '#') preR[i][j - 1] = preR[i][j]; } } } for (int i = 0; i < w; i++) { for (int j = h; j > 1; j--) { if (preC[j][i] != 0) { if (a[j - 2][i] != '#') { preC[j - 1][i] = preC[j][i]; } } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, preR[i][j + 1] + preC[i + 1][j] - 1); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int preC[maxn][maxn], preR[maxn][maxn]; int main() { int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) { cin >> a[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] != '#') preR[i][j + 1] = preR[i][j] + 1; } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (a[j][i] != '#') { preC[j + 1][i] = preC[j][i] + 1; } } } for (int i = 0; i < h; i++) { for (int j = w; j > 1; j--) { if (preR[i][j] != 0) { if (a[i][j - 2] != '#') preR[i][j - 1] = preR[i][j]; } } } for (int i = 0; i < w; i++) { for (int j = h; j > 1; j--) { if (preC[j][i] != 0) { if (a[j - 2][i] != '#') { preC[j - 1][i] = preC[j][i]; } } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, preR[i][j + 1] + preC[i + 1][j] - 1); } } cout << ans; return 0; }
replace
4
5
4
5
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); int light[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { light[i][j] = 0; } } for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < h; i++) { vector<int> memo(w); int cnt = 0; for (int j = 0; j < w; j++) { if (s[i][j] == '.') { cnt++; } else { memo[j] = cnt; cnt = 0; } } for (int j = w - 1; j >= 0; j--) { if (memo[j] == 0 && s[i][j] != '#') { light[i][j] += cnt; } else { cnt = memo[j]; } } } for (int j = 0; j < h; j++) { vector<int> memo(h); int cnt = 0; for (int i = 0; i < h; i++) { if (s[i][j] == '.') { cnt++; } else { memo[i] = cnt; cnt = 0; } } for (int i = h - 1; i >= 0; i--) { if (memo[i] == 0 && s[i][j] != '#') { light[i][j] += cnt; } else { cnt = memo[i]; } } } // for (int i=0; i<h; i++) { // for (int j=0; j<w; j++) { // cout << light[i][j] << " "; // } // cout << endl; // } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, light[i][j]); } } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); int light[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { light[i][j] = 0; } } for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < h; i++) { vector<int> memo(w); int cnt = 0; for (int j = 0; j < w; j++) { if (s[i][j] == '.') { cnt++; } else { memo[j] = cnt; cnt = 0; } } for (int j = w - 1; j >= 0; j--) { if (memo[j] == 0 && s[i][j] != '#') { light[i][j] += cnt; } else { cnt = memo[j]; } } } for (int j = 0; j < w; j++) { vector<int> memo(h); int cnt = 0; for (int i = 0; i < h; i++) { if (s[i][j] == '.') { cnt++; } else { memo[i] = cnt; cnt = 0; } } for (int i = h - 1; i >= 0; i--) { if (memo[i] == 0 && s[i][j] != '#') { light[i][j] += cnt; } else { cnt = memo[i]; } } } // for (int i=0; i<h; i++) { // for (int j=0; j<w; j++) { // cout << light[i][j] << " "; // } // cout << endl; // } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, light[i][j]); } } cout << ans - 1 << endl; return 0; }
replace
35
36
35
36
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); i++) signed main() { IOS; int h, w, ans = 0; cin >> h >> w; int hcnt[h + 1][w + 1], wcnt[h + 1][w + 1]; string s[w]; FOR(i, 0, h) { cin >> s[i]; int prev = -1, cnt = 0; FOR(j, 0, w) { if (s[i][j] == '.') { cnt++; } else { FOR(k, prev + 1, j) hcnt[i][k] = cnt; cnt = 0; hcnt[i][j] = 0; prev = j; } } FOR(k, prev + 1, w) hcnt[i][k] = cnt; // FOR(j,0,w) // cout << hcnt[i][j] << " "; // cout << endl; } FOR(j, 0, w) { int prev = -1, cnt = 0; FOR(i, 0, h) { if (s[i][j] == '.') { cnt++; } else { FOR(k, prev + 1, i) { wcnt[k][j] = cnt; ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1); } cnt = 0; wcnt[i][j] = 0; prev = i; } } FOR(k, prev + 1, h) { wcnt[k][j] = cnt; ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1); } } // cout << endl; // FOR(i,0,h) { // FOR(j,0,w) // cout << wcnt[i][j] << " "; // cout << endl; // } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); i++) signed main() { IOS; int h, w, ans = 0; cin >> h >> w; int hcnt[h + 1][w + 1], wcnt[h + 1][w + 1]; string s[h]; FOR(i, 0, h) { cin >> s[i]; int prev = -1, cnt = 0; FOR(j, 0, w) { if (s[i][j] == '.') { cnt++; } else { FOR(k, prev + 1, j) hcnt[i][k] = cnt; cnt = 0; hcnt[i][j] = 0; prev = j; } } FOR(k, prev + 1, w) hcnt[i][k] = cnt; // FOR(j,0,w) // cout << hcnt[i][j] << " "; // cout << endl; } FOR(j, 0, w) { int prev = -1, cnt = 0; FOR(i, 0, h) { if (s[i][j] == '.') { cnt++; } else { FOR(k, prev + 1, i) { wcnt[k][j] = cnt; ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1); } cnt = 0; wcnt[i][j] = 0; prev = i; } } FOR(k, prev + 1, h) { wcnt[k][j] = cnt; ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1); } } // cout << endl; // FOR(i,0,h) { // FOR(j,0,w) // cout << wcnt[i][j] << " "; // cout << endl; // } cout << ans << endl; return 0; }
replace
16
17
16
17
0
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; /*2進数配列+1*/ vector<int> twoadd(vector<int> v, int N) { v[N - 1] += 1; int ind = N - 1; int j = N - 1; for (j = N - 1; j >= 1; j--) { if (v[j] > 1) { v[j - 1] += 1; v[j] = 0; } } return v; } /*フィボナッチ*/ long long fibonatti(long long d) { long long count = 0; long long f1 = 1; long long f2 = 1; /*ここを変える*/ long long temp; if (d == 1) { count = f1; } else if (d == 2) { count = f2; } else if (d == 0) { count = 1; } else { for (int i = 0; i < d - 2; i++) { temp = f1 + f2; f1 = f2; f2 = temp; } count = temp; } return count; } /*ここから*/ int main() { int H, W; cin >> H >> W; vector<vector<int>> v(H, vector<int>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char w; cin >> w; if (w == '#') { v[i][j] = 1; } else { v[i][j] = 0; } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int count = 0; if (v[i][j] == 0) { for (int k = i; k < H; k++) { if (v[k][j] == 1) { break; } count++; } for (int k = i; k >= 0; k--) { if (v[k][j] == 1) { break; } count++; } for (int k = j; k < W; k++) { if (v[i][k] == 1) { break; } count++; } for (int k = j; k >= 0; k--) { if (v[i][k] == 1) { break; } count++; } } if (ans < count) { ans = count; } } } ans -= 3; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; /*2進数配列+1*/ vector<int> twoadd(vector<int> v, int N) { v[N - 1] += 1; int ind = N - 1; int j = N - 1; for (j = N - 1; j >= 1; j--) { if (v[j] > 1) { v[j - 1] += 1; v[j] = 0; } } return v; } /*フィボナッチ*/ long long fibonatti(long long d) { long long count = 0; long long f1 = 1; long long f2 = 1; /*ここを変える*/ long long temp; if (d == 1) { count = f1; } else if (d == 2) { count = f2; } else if (d == 0) { count = 1; } else { for (int i = 0; i < d - 2; i++) { temp = f1 + f2; f1 = f2; f2 = temp; } count = temp; } return count; } /*ここから*/ int main() { int H, W; cin >> H >> W; vector<vector<int>> v(H, vector<int>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char w; cin >> w; if (w == '#') { v[i][j] = 1; } else { v[i][j] = 0; } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int count = 0; if (v[i][j] == 0) { for (int k = i; k < H; k++) { if (v[k][j] == 1) { break; } count++; } for (int k = i; k >= 0; k--) { if (v[k][j] == 1) { break; } count++; } for (int k = j; k < W; k++) { if (v[i][k] == 1) { break; } count++; } for (int k = j; k >= 0; k--) { if (v[i][k] == 1) { break; } count++; } } if (ans < count) { ans = count; } if (ans == H + W + 2) { break; } } } ans -= 3; cout << ans << endl; }
insert
87
87
87
90
TLE
p03014
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<ll> vec; typedef vector<vec> vec2; typedef map<ll, ll> MPll; typedef set<ll> setl; const ll INF = 1ll << 60; const ld EPS = 1e-10; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mods = 1000000007; // for文 #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define FORE(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++) #define REP(i, size) for (ll i = (ll)0; i < size; i++) #define REPE(i, size) for (ll i = (ll)0; i <= size; i++) #define REPR(i, size) for (ll i = (ll)size; i >= 0; i--) #define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++) // ソート #define ALL(vec) (vec).begin(), (vec).end() #define SORT(vec) sort(ALL(vec)) #define SORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))) #define INVSORT(vec) sort((vec).rbegin(), (vec).rend()) #define REV(vec) reverse(ALL(vec)) #define REVA(arr) reverse(arr, arr + (sizeof(arr) / sizeof(ll))) #define INVSORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))), REVA(arr) // 最大値最小値 #define MAX(vec) *max_element(ALL(vec)) #define UNIQ(vec) \ SORT(vec); \ vec.erase(unique(ALL(vec)), vec.end()) #define MIN(vec) *min_element(ALL(vec)) // 出力 #define printl(a) cout << a << "\n" #define print(a) cout << a #define OUT(a) printf("%lld\n", a) #define OUTA(array) \ REP(i, sizeof(array) / sizeof(ll)) printf("%lld\n", array[i]) #define OUTV(vec) REP(i, vec.size()) printf("%lld\n", vec[i]) #define SP printf(" ") // 入力 #define IN(x) scanf("%lld", &x) #define INV(vec) REP(i, vec.size()) scanf("%lld", &vec[i]) #define INA(array) REP(i, sizeof(array) / sizeof(ll)) scanf("%lld", array + i) #define INS(x) cin >> x #define INCH(x) scanf(" %c", &x) // 型 #define P pair #define vp vector<P> #define F first #define S second // その他 #define PB push_back #define MP make_pair #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, -1, sizeof(a)) #define INFI(a) memset(a, INF, sizeof(a)) #define MEM(a, b) memset(a, (b), sizeof(a)) // 関数 template <class T> inline void amax(T &a, const T &b) { if (a < b) a = b; } template <class T> inline void amin(T &a, const T &b) { if (a > b) a = b; } /* struct structure{ ll num1,num2,string s; bool operator<(const rest &another) const{ return this->s < another.s; } structure(ll a,ll b,string s){ this->num1 = a,this->num2=b,this->s=s; } };a */ // 特殊 // #define int ll #define _CRT_SECURE_NO_WARNINGS /* template <typename T> struct UnionFindTree{ vector<T> par; UnionFindTree(T n) : par(n+1){ for (int i = 1; i <= n; ++i) { par[i] = i; } } T root(T x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } void unite(T x,T y){ if(!same(x,y)) par[root(x)] = root(par[y]); } T same(T x,T y){ return root(x) == root(y); } }; */ #define DEBUG #ifdef DEBUG #define debugl(x) cerr << #x << ":" << x << "\n" #define debug(x) cerr << x #define debugV(V) \ REP(i, V.size()) { cerr << i << ":" << V[i] << endl; } #define debugA(A) \ REP(i, sizeof(A) / sizeof(ll)) { cerr << i << ":" << V[i] << endl; } #else #define debug(x) #define debugV(x) #define debugA(x) #define debugl(x) #endif #define ZERO(a) memset(a, 0, sizeof(a)) #define ALL(vec) (vec).begin(), (vec).end() #define SORT(vec) sort(ALL(vec)) signed main() { ll H; ll W; IN(H); IN(W); string S[H + 2]; string temp; S[0] = '#'; S[H + 1] = '#'; FOR(i, 0, W + 2) S[0] += '#'; FOR(i, 0, W + 2) S[H + 1] += '#'; // cerr << S[0] << endl; FOR(i, 1, H + 1) { S[i] = "#"; cin >> temp; S[i] += temp; S[i] += "#"; // cerr << S[i] << endl; } // cerr << S[H+1] << endl; vec2 hidari(W + 2, vec(H + 2, 0)); vec2 migi(W + 2, vec(H + 2, 0)); vec2 ue(W + 2, vec(H + 2, 0)); vec2 sita(W + 2, vec(H + 2, 0)); FOR(h, 1, H + 1) FOR(w, 1, W + 1) { if (S[h][w] == '#') { hidari[h][w] = 0; } else { hidari[h][w] = hidari[h][w - 1] + 1; } } FOR(w, 1, W + 1) FOR(h, 1, H + 1) { if (S[h][w] == '#') { ue[h][w] = 0; } else { ue[h][w] = ue[h - 1][w] + 1; } } for (int w = W; w >= 1; --w) { for (int h = H; h >= 1; --h) { if (S[h][w] == '#') { sita[h][w] = 0; } else { sita[h][w] = sita[h + 1][w] + 1; } } } for (int h = H; h >= 1; --h) { for (int w = W; w >= 1; --w) { if (S[h][w] == '#') { migi[h][w] = 0; } else { migi[h][w] = migi[h][w + 1] + 1; } } } ll ans = 0; ll num = 0; FOR(w, 1, W + 1) FOR(h, 1, H + 1) { if (S[h][w] == '.') { num = migi[h][w] + hidari[h][w] + sita[h][w] + ue[h][w] - 3; // cerr <<w<<h<<","<< // migi[h][w]<<","<<hidari[h][w]<<","<<sita[h][w]<<","<<ue[h][w]<<endl; amax(ans, num); } } OUT(ans); }
#include <algorithm> #include <assert.h> #include <bitset> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<ll> vec; typedef vector<vec> vec2; typedef map<ll, ll> MPll; typedef set<ll> setl; const ll INF = 1ll << 60; const ld EPS = 1e-10; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mods = 1000000007; // for文 #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define FORE(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++) #define REP(i, size) for (ll i = (ll)0; i < size; i++) #define REPE(i, size) for (ll i = (ll)0; i <= size; i++) #define REPR(i, size) for (ll i = (ll)size; i >= 0; i--) #define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++) // ソート #define ALL(vec) (vec).begin(), (vec).end() #define SORT(vec) sort(ALL(vec)) #define SORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))) #define INVSORT(vec) sort((vec).rbegin(), (vec).rend()) #define REV(vec) reverse(ALL(vec)) #define REVA(arr) reverse(arr, arr + (sizeof(arr) / sizeof(ll))) #define INVSORTA(arr) sort(arr, arr + (sizeof(arr) / sizeof(ll))), REVA(arr) // 最大値最小値 #define MAX(vec) *max_element(ALL(vec)) #define UNIQ(vec) \ SORT(vec); \ vec.erase(unique(ALL(vec)), vec.end()) #define MIN(vec) *min_element(ALL(vec)) // 出力 #define printl(a) cout << a << "\n" #define print(a) cout << a #define OUT(a) printf("%lld\n", a) #define OUTA(array) \ REP(i, sizeof(array) / sizeof(ll)) printf("%lld\n", array[i]) #define OUTV(vec) REP(i, vec.size()) printf("%lld\n", vec[i]) #define SP printf(" ") // 入力 #define IN(x) scanf("%lld", &x) #define INV(vec) REP(i, vec.size()) scanf("%lld", &vec[i]) #define INA(array) REP(i, sizeof(array) / sizeof(ll)) scanf("%lld", array + i) #define INS(x) cin >> x #define INCH(x) scanf(" %c", &x) // 型 #define P pair #define vp vector<P> #define F first #define S second // その他 #define PB push_back #define MP make_pair #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, -1, sizeof(a)) #define INFI(a) memset(a, INF, sizeof(a)) #define MEM(a, b) memset(a, (b), sizeof(a)) // 関数 template <class T> inline void amax(T &a, const T &b) { if (a < b) a = b; } template <class T> inline void amin(T &a, const T &b) { if (a > b) a = b; } /* struct structure{ ll num1,num2,string s; bool operator<(const rest &another) const{ return this->s < another.s; } structure(ll a,ll b,string s){ this->num1 = a,this->num2=b,this->s=s; } };a */ // 特殊 // #define int ll #define _CRT_SECURE_NO_WARNINGS /* template <typename T> struct UnionFindTree{ vector<T> par; UnionFindTree(T n) : par(n+1){ for (int i = 1; i <= n; ++i) { par[i] = i; } } T root(T x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } void unite(T x,T y){ if(!same(x,y)) par[root(x)] = root(par[y]); } T same(T x,T y){ return root(x) == root(y); } }; */ #define DEBUG #ifdef DEBUG #define debugl(x) cerr << #x << ":" << x << "\n" #define debug(x) cerr << x #define debugV(V) \ REP(i, V.size()) { cerr << i << ":" << V[i] << endl; } #define debugA(A) \ REP(i, sizeof(A) / sizeof(ll)) { cerr << i << ":" << V[i] << endl; } #else #define debug(x) #define debugV(x) #define debugA(x) #define debugl(x) #endif #define ZERO(a) memset(a, 0, sizeof(a)) #define ALL(vec) (vec).begin(), (vec).end() #define SORT(vec) sort(ALL(vec)) signed main() { ll H; ll W; IN(H); IN(W); string S[H + 2]; string temp; S[0] = '#'; S[H + 1] = '#'; FOR(i, 0, W + 2) S[0] += '#'; FOR(i, 0, W + 2) S[H + 1] += '#'; // cerr << S[0] << endl; FOR(i, 1, H + 1) { S[i] = "#"; cin >> temp; S[i] += temp; S[i] += "#"; // cerr << S[i] << endl; } // cerr << S[H+1] << endl; vec2 hidari(H + 2, vec(W + 2, 0)); vec2 migi(H + 2, vec(W + 2, 0)); vec2 ue(H + 2, vec(W + 2, 0)); vec2 sita(H + 2, vec(W + 2, 0)); FOR(h, 1, H + 1) FOR(w, 1, W + 1) { if (S[h][w] == '#') { hidari[h][w] = 0; } else { hidari[h][w] = hidari[h][w - 1] + 1; } } FOR(w, 1, W + 1) FOR(h, 1, H + 1) { if (S[h][w] == '#') { ue[h][w] = 0; } else { ue[h][w] = ue[h - 1][w] + 1; } } for (int w = W; w >= 1; --w) { for (int h = H; h >= 1; --h) { if (S[h][w] == '#') { sita[h][w] = 0; } else { sita[h][w] = sita[h + 1][w] + 1; } } } for (int h = H; h >= 1; --h) { for (int w = W; w >= 1; --w) { if (S[h][w] == '#') { migi[h][w] = 0; } else { migi[h][w] = migi[h][w + 1] + 1; } } } ll ans = 0; ll num = 0; FOR(w, 1, W + 1) FOR(h, 1, H + 1) { if (S[h][w] == '.') { num = migi[h][w] + hidari[h][w] + sita[h][w] + ue[h][w] - 3; // cerr <<w<<h<<","<< // migi[h][w]<<","<<hidari[h][w]<<","<<sita[h][w]<<","<<ue[h][w]<<endl; amax(ans, num); } } OUT(ans); }
replace
191
195
191
195
0
p03014
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define reps(i, x) for (int i = 1; i <= (int)(x); i++) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define rreps(i, x) for (int i = ((int)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; using ll = long long; int main() { // 入力、初期化 int H, W; cin >> H >> W; vector<vector<int>> cnt(H, vector<int>(W)); vector<string> s(H); rep(i, H) { cin >> s[i]; } rep(i, H) { vector<int> done(W); rep(j, W) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < W) { if (s[i][j + l] == '#') break; l++; } rep(k, l) { cnt[i][j + k] += l; done[j + k] = 1; } } } rep(j, W) { vector<int> done(W); rep(i, H) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < H) { if (s[i + l][j] == '#') break; l++; } rep(k, l) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; rep(i, H) rep(j, W) ans = max(ans, cnt[i][j] - 1); cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define reps(i, x) for (int i = 1; i <= (int)(x); i++) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define rreps(i, x) for (int i = ((int)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; using ll = long long; int main() { // 入力、初期化 int H, W; cin >> H >> W; vector<vector<int>> cnt(H, vector<int>(W)); vector<string> s(H); rep(i, H) { cin >> s[i]; } rep(i, H) { vector<int> done(W); rep(j, W) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < W) { if (s[i][j + l] == '#') break; l++; } rep(k, l) { cnt[i][j + k] += l; done[j + k] = 1; } } } rep(j, W) { vector<int> done(H); rep(i, H) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < H) { if (s[i + l][j] == '#') break; l++; } rep(k, l) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; rep(i, H) rep(j, W) ans = max(ans, cnt[i][j] - 1); cout << ans << endl; return 0; }
replace
61
62
61
62
0
p03014
C++
Runtime Error
#include <iostream> #include <string> using namespace std; const int MAX_H = 2000; const int MAX_W = 2000; int H, W, v[MAX_H][MAX_W], h[MAX_H][MAX_W]; string M[MAX_H]; int dfs_v(int y, int x, int num) { if (v[y][x] != 0) return v[y][x]; if (M[y][x] == '#' || y >= H) return num; return v[y][x] = dfs_v(y + 1, x, num + 1); } int dfs_h(int y, int x, int num) { if (h[y][x] != 0) return h[y][x]; if (M[y][x] == '#' || x >= W) return num; return h[y][x] = dfs_h(y, x + 1, num + 1); } int main() { for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { v[i][j] = 0; h[i][j] = 0; } } cin >> H >> W; for (int i = 0; i < H; ++i) { cin >> M[i]; } int ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { ans = max(ans, dfs_v(i, j, 0) + dfs_h(i, j, 0) - 1); } } cout << ans << endl; }
#include <iostream> #include <string> using namespace std; const int MAX_H = 2010; const int MAX_W = 2010; int H, W, v[MAX_H][MAX_W], h[MAX_H][MAX_W]; string M[MAX_H]; int dfs_v(int y, int x, int num) { if (v[y][x] != 0) return v[y][x]; if (M[y][x] == '#' || y >= H) return num; return v[y][x] = dfs_v(y + 1, x, num + 1); } int dfs_h(int y, int x, int num) { if (h[y][x] != 0) return h[y][x]; if (M[y][x] == '#' || x >= W) return num; return h[y][x] = dfs_h(y, x + 1, num + 1); } int main() { for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { v[i][j] = 0; h[i][j] = 0; } } cin >> H >> W; for (int i = 0; i < H; ++i) { cin >> M[i]; } int ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { ans = max(ans, dfs_v(i, j, 0) + dfs_h(i, j, 0) - 1); } } cout << ans << endl; }
replace
4
6
4
6
0
p03014
C++
Runtime Error
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { int H, W, x = 0, y = 0; cin >> H >> W; vector<string> S(H); int a[200][200] = {0}, b[200][200] = {0}; for (int i = 0; i < H; i++) cin >> S[i]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') { x = 0; while (j + x < W && S[i][j + x] != '#') x++; while (j < W && S[i][j] != '#') { a[i][j] = x; j++; } } } } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (S[j][i] == '.') { x = 0; while (j + x < H && S[j + x][i] != '#') x++; while (j < H && S[j][i] != '#') { b[j][i] = x; j++; } } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(ans, a[i][j] + b[i][j]); } } cout << ans - 1 << endl; }
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { int H, W, x = 0, y = 0; cin >> H >> W; vector<string> S(H); int a[2001][2001] = {0}, b[2001][2001] = {0}; for (int i = 0; i < H; i++) cin >> S[i]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') { x = 0; while (j + x < W && S[i][j + x] != '#') x++; while (j < W && S[i][j] != '#') { a[i][j] = x; j++; } } } } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (S[j][i] == '.') { x = 0; while (j + x < H && S[j + x][i] != '#') x++; while (j < H && S[j][i] != '#') { b[j][i] = x; j++; } } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(ans, a[i][j] + b[i][j]); } } cout << ans - 1 << endl; }
replace
17
18
17
18
0
p03014
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #pragma warning(disable : 4996) #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const double PI = 3.14159265358979323846; const int MAX = 1e7; const int MOD = 1e9 + 7; int main(int argc, char *args[]) { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) cin >> s[i]; vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < w) { if (s[i][j + l] == '#') break; ++l; } for (int k = 0; k < l; k++) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(w); for (int i = 0; i < h; i++) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; ++l; } for (int k = 0; k < l; k++) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt[i][j] - 1); } } cout << ans << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #pragma warning(disable : 4996) #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const double PI = 3.14159265358979323846; const int MAX = 1e7; const int MOD = 1e9 + 7; int main(int argc, char *args[]) { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) cin >> s[i]; vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < w) { if (s[i][j + l] == '#') break; ++l; } for (int k = 0; k < l; k++) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(h); for (int i = 0; i < h; i++) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; ++l; } for (int k = 0; k < l; k++) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt[i][j] - 1); } } cout << ans << endl; return 0; }
replace
57
58
57
58
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mx 100000 int main() { int n, m; cin >> n >> m; char ar[n + 2][m + 2]; for (int i = 1; i <= n; i++) { scanf("%s", ar[i] + 1); } int row[n + 2][m + 2]; int col[n + 2][m + 2]; memset(row, 0, sizeof row); memset(col, 0, sizeof col); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (ar[i][j] == '.') { col[i][j] = col[i][j - 1] + 1; row[i][j] = row[i - 1][j] + 1; } } } for (int i = 1; i <= n; i++) { // for(int j=1;j<=m;j++)cout<<row[i][j]; // cout<<endl; } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (ar[i][j] == '#') continue; int lo = 1, hi = j; int res = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (row[i][j] - row[mid - 1][j] == i - mid + 1) { hi = mid - 1; res = max(res, i - mid); } else lo = mid + 1; } lo = i, hi = n; int res1 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (row[mid][j] - row[i - 1][j] == mid - i + 1) { lo = mid + 1; res1 = max(res1, mid - i); } else hi = mid - 1; } lo = 1, hi = j; int res2 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (col[i][j] - col[i][mid - 1] == j - mid + 1) { hi = mid - 1; res2 = max(res2, j - mid); } else lo = mid + 1; } lo = j, hi = m; int res3 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (col[i][mid] - col[i][j - 1] == mid - j + 1) { lo = mid + 1; res3 = max(res3, mid - j); } else hi = mid - 1; } // if(i==2&&j==2)cout<<res<<res1<<res2<<res3<<endl; ans = max(ans, 1 + res + res1 + res2 + res3); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mx 100000 int main() { int n, m; cin >> n >> m; char ar[n + 2][m + 2]; for (int i = 1; i <= n; i++) { scanf("%s", ar[i] + 1); } int row[n + 2][m + 2]; int col[n + 2][m + 2]; memset(row, 0, sizeof row); memset(col, 0, sizeof col); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (ar[i][j] == '.') { col[i][j] = col[i][j - 1] + 1; row[i][j] = row[i - 1][j] + 1; } } } for (int i = 1; i <= n; i++) { // for(int j=1;j<=m;j++)cout<<row[i][j]; // cout<<endl; } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (ar[i][j] == '#') continue; int lo = 1, hi = i; int res = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (row[i][j] - row[mid - 1][j] == i - mid + 1) { hi = mid - 1; res = max(res, i - mid); } else lo = mid + 1; } lo = i, hi = n; int res1 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (row[mid][j] - row[i - 1][j] == mid - i + 1) { lo = mid + 1; res1 = max(res1, mid - i); } else hi = mid - 1; } lo = 1, hi = j; int res2 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (col[i][j] - col[i][mid - 1] == j - mid + 1) { hi = mid - 1; res2 = max(res2, j - mid); } else lo = mid + 1; } lo = j, hi = m; int res3 = 0; while (lo <= hi) { int mid = (lo + hi) / 2; if (col[i][mid] - col[i][j - 1] == mid - j + 1) { lo = mid + 1; res3 = max(res3, mid - j); } else hi = mid - 1; } // if(i==2&&j==2)cout<<res<<res1<<res2<<res3<<endl; ans = max(ans, 1 + res + res1 + res2 + res3); } } cout << ans << endl; return 0; }
replace
45
46
45
46
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int h, w; int i, j, k; cin >> h >> w; vector<string> s(h); for (i = 0; i < h; ++i) { cin >> s.at(i); } vector<vector<int>> tate(h, vector<int>(w, 0)); vector<vector<int>> yoko(h, vector<int>(w, 0)); for (i = 0; i < w; ++i) { vector<int> v; for (j = 0; j < h; ++j) { if (s.at(j).at(i) == '#') { v.push_back(j); } } if (v.size() == 0) { for (j = 0; j < h; ++j) { tate.at(j).at(i) = h; } continue; } for (j = 0; j < v.at(0); ++j) { tate.at(j).at(i) = v.at(0); } tate.at(v.at(0)).at(i) = 0; for (k = 0; k < v.size() - 1; ++k) { for (j = v.at(k) + 1; j < v.at(k + 1); ++j) { tate.at(j).at(i) = v.at(k + 1) - v.at(k) - 1; } tate.at(v.at(k + 1)).at(i) = 0; } for (k = v.at(v.size() - 1) + 1; k < h; ++k) { tate.at(k).at(i) = h - 1 - v.at(v.size() - 1); } } for (i = 0; i < h; ++i) { vector<int> v; for (j = 0; j < w; ++j) { if (s.at(i).at(j) == '#') { v.push_back(j); } } if (v.size() == 0) { for (j = 0; j < h; ++j) { yoko.at(i).at(j) = w; } continue; } for (j = 0; j < v.at(0); ++j) { yoko.at(i).at(j) = v.at(0); } yoko.at(i).at(v.at(0)) = 0; for (k = 0; k < v.size() - 1; ++k) { for (j = v.at(k) + 1; j < v.at(k + 1); ++j) { yoko.at(i).at(j) = v.at(k + 1) - v.at(k) - 1; } yoko.at(i).at(v.at(k + 1)) = 0; } for (k = v.at(v.size() - 1) + 1; k < w; ++k) { yoko.at(i).at(k) = w - 1 - v.at(v.size() - 1); } } int ans = 0; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { if (ans < tate.at(i).at(j) + yoko.at(i).at(j) - 1) { ans = tate.at(i).at(j) + yoko.at(i).at(j) - 1; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int h, w; int i, j, k; cin >> h >> w; vector<string> s(h); for (i = 0; i < h; ++i) { cin >> s.at(i); } vector<vector<int>> tate(h, vector<int>(w, 0)); vector<vector<int>> yoko(h, vector<int>(w, 0)); for (i = 0; i < w; ++i) { vector<int> v; for (j = 0; j < h; ++j) { if (s.at(j).at(i) == '#') { v.push_back(j); } } if (v.size() == 0) { for (j = 0; j < h; ++j) { tate.at(j).at(i) = h; } continue; } for (j = 0; j < v.at(0); ++j) { tate.at(j).at(i) = v.at(0); } tate.at(v.at(0)).at(i) = 0; for (k = 0; k < v.size() - 1; ++k) { for (j = v.at(k) + 1; j < v.at(k + 1); ++j) { tate.at(j).at(i) = v.at(k + 1) - v.at(k) - 1; } tate.at(v.at(k + 1)).at(i) = 0; } for (k = v.at(v.size() - 1) + 1; k < h; ++k) { tate.at(k).at(i) = h - 1 - v.at(v.size() - 1); } } for (i = 0; i < h; ++i) { vector<int> v; for (j = 0; j < w; ++j) { if (s.at(i).at(j) == '#') { v.push_back(j); } } if (v.size() == 0) { for (j = 0; j < w; ++j) { yoko.at(i).at(j) = w; } continue; } for (j = 0; j < v.at(0); ++j) { yoko.at(i).at(j) = v.at(0); } yoko.at(i).at(v.at(0)) = 0; for (k = 0; k < v.size() - 1; ++k) { for (j = v.at(k) + 1; j < v.at(k + 1); ++j) { yoko.at(i).at(j) = v.at(k + 1) - v.at(k) - 1; } yoko.at(i).at(v.at(k + 1)) = 0; } for (k = v.at(v.size() - 1) + 1; k < w; ++k) { yoko.at(i).at(k) = w - 1 - v.at(v.size() - 1); } } int ans = 0; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { if (ans < tate.at(i).at(j) + yoko.at(i).at(j) - 1) { ans = tate.at(i).at(j) + yoko.at(i).at(j) - 1; } } } cout << ans << endl; return 0; }
replace
50
51
50
51
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF INT_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() int main() { ios::sync_with_stdio(false); cin.tie(0); int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) cin >> S[i]; vector<vector<ll>> sum(H, vector<ll>(W)); for (int i = 0; i < H; i++) { vector<ll> tor(W, 0); for (int j = 0; j < W; j++) { if (j == 0 && S[i][j] == '.') tor[j] = 1; else if (j != 0 && S[i][j] == '.') tor[j] = tor[j - 1] + 1; else tor[j] = 0; } vector<ll> tol(W, 0); for (int j = W - 1; j >= 0; j--) { if (j == W - 1 && S[i][j] == '.') tol[j] = 1; else if (j != W - 1 && S[i][j] == '.') tol[j] = tol[j + 1] + 1; else tol[j] = 0; } vector<ll> res(W, 0); for (int j = 0; j < W; j++) { res[j] = max(tol[j], tor[j]); } for (int j = 1; j < W; j++) { if (S[i][j] == '.') res[j] = max(res[j - 1], res[j]); } for (int j = W - 2; j >= 0; j--) { if (S[i][j] == '.') res[j] = max(res[j + 1], res[j]); } sum[i] = res; } for (int i = 0; i < W; i++) { vector<ll> tod(H, 0); for (int j = 0; j < H; j++) { if (j == 0 && S[j][i] == '.') tod[j] = 1; else if (j != 0 && S[j][i] == '.') tod[j] = tod[j - 1] + 1; else tod[j] = 0; } vector<ll> tou(H, 0); for (int j = H - 1; j >= 0; j--) { if (j == H - 1 && S[j][i] == '.') tou[j] = 1; else if (j != H - 1 && S[j][i] == '.') tou[j] = tou[j + 1] + 1; else tou[j] = 0; } vector<ll> res(W); for (int j = 0; j < H; j++) { res[j] = max(tod[j], tou[j]); } for (int j = 1; j < H; j++) { if (S[j][i] == '.') res[j] = max(res[j - 1], res[j]); } for (int j = H - 2; j >= 0; j--) { if (S[j][i] == '.') res[j] = max(res[j + 1], res[j]); } for (int j = 0; j < H; j++) { sum[j][i] += res[j]; } } ll ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (sum[i][j] != 0) sum[i][j]--; ans = max(ans, sum[i][j]); // cout<<sum[i][j]<<" "; } // cout<<endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF INT_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() int main() { ios::sync_with_stdio(false); cin.tie(0); int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) cin >> S[i]; vector<vector<ll>> sum(H, vector<ll>(W)); for (int i = 0; i < H; i++) { vector<ll> tor(W, 0); for (int j = 0; j < W; j++) { if (j == 0 && S[i][j] == '.') tor[j] = 1; else if (j != 0 && S[i][j] == '.') tor[j] = tor[j - 1] + 1; else tor[j] = 0; } vector<ll> tol(W, 0); for (int j = W - 1; j >= 0; j--) { if (j == W - 1 && S[i][j] == '.') tol[j] = 1; else if (j != W - 1 && S[i][j] == '.') tol[j] = tol[j + 1] + 1; else tol[j] = 0; } vector<ll> res(W, 0); for (int j = 0; j < W; j++) { res[j] = max(tol[j], tor[j]); } for (int j = 1; j < W; j++) { if (S[i][j] == '.') res[j] = max(res[j - 1], res[j]); } for (int j = W - 2; j >= 0; j--) { if (S[i][j] == '.') res[j] = max(res[j + 1], res[j]); } sum[i] = res; } for (int i = 0; i < W; i++) { vector<ll> tod(H, 0); for (int j = 0; j < H; j++) { if (j == 0 && S[j][i] == '.') tod[j] = 1; else if (j != 0 && S[j][i] == '.') tod[j] = tod[j - 1] + 1; else tod[j] = 0; } vector<ll> tou(H, 0); for (int j = H - 1; j >= 0; j--) { if (j == H - 1 && S[j][i] == '.') tou[j] = 1; else if (j != H - 1 && S[j][i] == '.') tou[j] = tou[j + 1] + 1; else tou[j] = 0; } vector<ll> res(H); for (int j = 0; j < H; j++) { res[j] = max(tod[j], tou[j]); } for (int j = 1; j < H; j++) { if (S[j][i] == '.') res[j] = max(res[j - 1], res[j]); } for (int j = H - 2; j >= 0; j--) { if (S[j][i] == '.') res[j] = max(res[j + 1], res[j]); } for (int j = 0; j < H; j++) { sum[j][i] += res[j]; } } ll ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (sum[i][j] != 0) sum[i][j]--; ans = max(ans, sum[i][j]); // cout<<sum[i][j]<<" "; } // cout<<endl; } cout << ans << endl; return 0; }
replace
75
76
75
76
0
p03014
C++
Runtime Error
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <vector> static const int IINF = 1 << 30; static const long long LINF = 1LL << 60; static const long long MOD = 1.0e+9 + 7; template <typename T> std::vector<T> vectors(std::size_t n, T val) { return std::vector<T>(n, val); } template <typename T, typename... Args> auto vectors(std::size_t n, Args... args) { return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...)); } template <class T> inline bool chmin(T &a, const T &b) { return (a > b) ? a = b, true : false; } template <class T> inline bool chmax(T &a, const T &b) { return (a < b) ? a = b, true : false; } template <class T> inline void chadd(T &a, const T &b) { a += b, a %= MOD; // TODO minus case } template <class T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { if (v.empty()) return s; s << *v.begin(); for (auto iter = v.begin() + 1; iter != v.end(); ++iter) if (std::is_fundamental<T>::value) s << " " << *iter; else s << std::endl << *iter; return s; } int main() { // Input int H, W; std::cin >> H >> W; std::vector<std::string> S(H); for (int i = 0; i < H; ++i) std::cin >> S[i]; std::vector<std::vector<char>> B(1 + H + 1); B[0] = std::vector<char>(1 + W + 1, '-'); B[H + 1] = std::vector<char>(1 + W + 1, '-'); for (int i = 1; i <= H; ++i) { B[i].assign(1 + W + 1, '-'); for (int j = 1; j <= W; ++j) B[i][j] = S[i - 1][j - 1]; } // Main std::vector<std::vector<int>> yoko(1 + H + 1); std::vector<std::vector<int>> tate(1 + H + 1); for (int i = 0; i <= H + 1; ++i) { yoko[i].assign(1 + W + 1, 0); tate[i].assign(1 + H + 1, 0); } // Yoko for (int i = 1; i <= H; ++i) { std::vector<int> left; std::vector<int> right; bool on = false; for (int j = 0; j <= W + 1; ++j) { if (not on and B[i][j] == '.') { // Startup left.push_back(j); on = true; } else if (on and B[i][j] != '.') { // Shutdown right.push_back(j); on = false; } } // assert(left.size() == right.size()); for (int k = 0; k < left.size(); ++k) { int l = left[k]; int r = right[k]; for (int j = l; j < r; ++j) { yoko[i][j] = r - l; } } } // Tate for (int j = 1; j <= W; ++j) { std::vector<int> left; std::vector<int> right; bool on = false; for (int i = 0; i <= H + 1; ++i) { if (not on and B[i][j] == '.') { left.push_back(i); on = true; } else if (on and B[i][j] != '.') { right.push_back(i); on = false; } } // assert(left.size() == right.size()); for (int k = 0; k < left.size(); ++k) { int l = left[k]; int r = right[k]; for (int i = l; i < r; ++i) { tate[i][j] = r - l; } } } // Output int res = 0; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { if (B[i][j] != '.') continue; chmax(res, yoko[i][j] + tate[i][j] - 1); } } std::cout << res << std::endl; return 0; }
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <vector> static const int IINF = 1 << 30; static const long long LINF = 1LL << 60; static const long long MOD = 1.0e+9 + 7; template <typename T> std::vector<T> vectors(std::size_t n, T val) { return std::vector<T>(n, val); } template <typename T, typename... Args> auto vectors(std::size_t n, Args... args) { return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...)); } template <class T> inline bool chmin(T &a, const T &b) { return (a > b) ? a = b, true : false; } template <class T> inline bool chmax(T &a, const T &b) { return (a < b) ? a = b, true : false; } template <class T> inline void chadd(T &a, const T &b) { a += b, a %= MOD; // TODO minus case } template <class T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { if (v.empty()) return s; s << *v.begin(); for (auto iter = v.begin() + 1; iter != v.end(); ++iter) if (std::is_fundamental<T>::value) s << " " << *iter; else s << std::endl << *iter; return s; } int main() { // Input int H, W; std::cin >> H >> W; std::vector<std::string> S(H); for (int i = 0; i < H; ++i) std::cin >> S[i]; std::vector<std::vector<char>> B(1 + H + 1); B[0] = std::vector<char>(1 + W + 1, '-'); B[H + 1] = std::vector<char>(1 + W + 1, '-'); for (int i = 1; i <= H; ++i) { B[i].assign(1 + W + 1, '-'); for (int j = 1; j <= W; ++j) B[i][j] = S[i - 1][j - 1]; } // Main std::vector<std::vector<int>> yoko(1 + H + 1); std::vector<std::vector<int>> tate(1 + H + 1); for (int i = 0; i <= H + 1; ++i) { yoko[i].assign(1 + W + 1, 0); tate[i].assign(1 + W + 1, 0); } // Yoko for (int i = 1; i <= H; ++i) { std::vector<int> left; std::vector<int> right; bool on = false; for (int j = 0; j <= W + 1; ++j) { if (not on and B[i][j] == '.') { // Startup left.push_back(j); on = true; } else if (on and B[i][j] != '.') { // Shutdown right.push_back(j); on = false; } } // assert(left.size() == right.size()); for (int k = 0; k < left.size(); ++k) { int l = left[k]; int r = right[k]; for (int j = l; j < r; ++j) { yoko[i][j] = r - l; } } } // Tate for (int j = 1; j <= W; ++j) { std::vector<int> left; std::vector<int> right; bool on = false; for (int i = 0; i <= H + 1; ++i) { if (not on and B[i][j] == '.') { left.push_back(i); on = true; } else if (on and B[i][j] != '.') { right.push_back(i); on = false; } } // assert(left.size() == right.size()); for (int k = 0; k < left.size(); ++k) { int l = left[k]; int r = right[k]; for (int i = l; i < r; ++i) { tate[i][j] = r - l; } } } // Output int res = 0; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { if (B[i][j] != '.') continue; chmax(res, yoko[i][j] + tate[i][j] - 1); } } std::cout << res << std::endl; return 0; }
replace
67
68
67
68
-6
free(): invalid next size (fast)
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000; int n, m; int s[MAXN][MAXN], s1[MAXN][MAXN]; int t[MAXN][MAXN], t1[MAXN][MAXN]; char str[MAXN][MAXN]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str[i][j] == '.') { s[i][j] = s[i][j - 1] + 1; t[i][j] = t[i - 1][j] + 1; } } } for (int i = n; i >= 1; i--) for (int j = m; j >= 1; j--) { if (str[i][j] == '.') { s1[i][j] = s1[i][j + 1] + 1; t1[i][j] = t1[i + 1][j] + 1; // cout<<i<<" "<<j<<" "<<s1[i][j]<<" "<<t1[i][j]<<endl; } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str[i][j] == '.') ans = max(ans, s[i][j] + s1[i][j] + t[i][j] + t1[i][j] - 3); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 4000; int n, m; int s[MAXN][MAXN], s1[MAXN][MAXN]; int t[MAXN][MAXN], t1[MAXN][MAXN]; char str[MAXN][MAXN]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str[i][j] == '.') { s[i][j] = s[i][j - 1] + 1; t[i][j] = t[i - 1][j] + 1; } } } for (int i = n; i >= 1; i--) for (int j = m; j >= 1; j--) { if (str[i][j] == '.') { s1[i][j] = s1[i][j + 1] + 1; t1[i][j] = t1[i + 1][j] + 1; // cout<<i<<" "<<j<<" "<<s1[i][j]<<" "<<t1[i][j]<<endl; } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str[i][j] == '.') ans = max(ans, s[i][j] + s1[i][j] + t[i][j] + t1[i][j] - 3); } } cout << ans; return 0; }
replace
2
3
2
3
0
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF 2147483647 #define INFF 9223372036854775807 #define ll long long #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, m, n) for (int i = m; i < n; i++) #define ALL(N) (N.begin(), N.end()) #define de cout << "debug" << endl; #define pb push_back template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int H, W; vector<vector<char>> glid(2003, vector<char>(2003)); int ue = 0, sita = 0; int migi = 0, hida = 0; int ans = 0; int cnt = 0; int solveup(int X, int Y) { if (glid[X - 1][Y] == '.') { ue++; solveup(X - 1, Y); } else { return ue; } } int solvedown(int X, int Y) { if (glid[X + 1][Y] == '.') { sita++; solvedown(X + 1, Y); } else { return sita; } } int solveright(int X, int Y) { if (glid[X][Y + 1] == '.') { migi++; solveright(X, Y + 1); } else { return migi; } } int solveleft(int X, int Y) { if (glid[X][Y - 1] == '.') { hida++; solveleft(X, Y - 1); } else { return hida; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; REPP(i, 1, H + 1) { REPP(j, 1, W + 1) { cin >> glid[i][j]; } } REP(i, H + 2) { glid[i][0] == '#'; } REP(i, W + 2) { glid[0][i] == '#'; } int maxv = 0; REP(i, H + 2) { REP(j, W + 2) { if (glid[i][j] == '.') { ans += solveup(i, j); ans += solvedown(i, j); ans += solveright(i, j); ans += solveleft(i, j); maxv = max(maxv, ans); ans = 0; ue = 0; sita = 0; migi = 0; hida = 0; } } } cout << maxv + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define INF 2147483647 #define INFF 9223372036854775807 #define ll long long #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, m, n) for (int i = m; i < n; i++) #define ALL(N) (N.begin(), N.end()) #define de cout << "debug" << endl; #define pb push_back template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int H, W; vector<vector<char>> glid(2003, vector<char>(2003)); int ue = 0, sita = 0; int migi = 0, hida = 0; int ans = 0; int cnt = 0; int solveup(int X, int Y) { if (glid[X - 1][Y] == '.') { ue++; solveup(X - 1, Y); } else { return ue; } } int solvedown(int X, int Y) { if (glid[X + 1][Y] == '.') { sita++; solvedown(X + 1, Y); } else { return sita; } } int solveright(int X, int Y) { if (glid[X][Y + 1] == '.') { migi++; solveright(X, Y + 1); } else { return migi; } } int solveleft(int X, int Y) { if (glid[X][Y - 1] == '.') { hida++; solveleft(X, Y - 1); } else { return hida; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; REPP(i, 1, H + 1) { REPP(j, 1, W + 1) { cin >> glid[i][j]; } } REP(i, H + 2) { glid[i][0] == '#'; } REP(i, W + 2) { glid[0][i] == '#'; } int maxv = 0; REP(i, H + 2) { REP(j, W + 2) { if (glid[i][j] == '.') { ans += solveup(i, j); ans += solvedown(i, j); ans += solveright(i, j); ans += solveleft(i, j); maxv = max(maxv, ans); if (maxv == H + W - 2) { cout << maxv + 1 << endl; return 0; } ans = 0; ue = 0; sita = 0; migi = 0; hida = 0; } } } cout << maxv + 1 << endl; }
insert
87
87
87
91
TLE
p03014
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector<vector<int>> L(H, vector<int>(W)); vector<vector<int>> R(H, vector<int>(W)); vector<vector<int>> U(H, vector<int>(W)); vector<vector<int>> D(H, vector<int>(W)); for (int i = 0; i < H; i++) { int cnt = 0; for (int j = 0; j < W; j++) { if (S[i][j] == '#') { cnt = 0; } else { cnt++; } L[i][j] = cnt; } } for (int i = 0; i < H; i++) { int cnt = 0; for (int j = W - 1; j >= 0; j--) { if (S[i][j] == '#') { cnt = 0; } else { cnt++; } R[i][j] = cnt; } } for (int i = 0; i < W; i++) { int cnt = 0; for (int j = 0; j < H; j++) { if (S[j][i] == '#') { cnt = 0; } else { cnt++; } U[j][i] = cnt; } } for (int i = 0; i < W; i++) { int cnt = 0; for (int j = H - 1; j >= 0; j--) { if (S[j][i] == '#') { cnt = 0; } else { cnt++; } D[i][j] = cnt; } } int max_sum = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int c = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3; max_sum = max(c, max_sum); } } cout << max_sum << endl; return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector<vector<int>> L(H, vector<int>(W)); vector<vector<int>> R(H, vector<int>(W)); vector<vector<int>> U(H, vector<int>(W)); vector<vector<int>> D(H, vector<int>(W)); for (int i = 0; i < H; i++) { int cnt = 0; for (int j = 0; j < W; j++) { if (S[i][j] == '#') { cnt = 0; } else { cnt++; } L[i][j] = cnt; } } for (int i = 0; i < H; i++) { int cnt = 0; for (int j = W - 1; j >= 0; j--) { if (S[i][j] == '#') { cnt = 0; } else { cnt++; } R[i][j] = cnt; } } for (int i = 0; i < W; i++) { int cnt = 0; for (int j = 0; j < H; j++) { if (S[j][i] == '#') { cnt = 0; } else { cnt++; } U[j][i] = cnt; } } for (int i = 0; i < W; i++) { int cnt = 0; for (int j = H - 1; j >= 0; j--) { if (S[j][i] == '#') { cnt = 0; } else { cnt++; } D[j][i] = cnt; } } int max_sum = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int c = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3; max_sum = max(c, max_sum); } } cout << max_sum << endl; return 0; }
replace
65
66
65
66
-11
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++) #define memi cout << endl #define kono(n) cout << fixed << setprecision(n) #define all(c) (c).begin(), (c).end() #define pb push_back #define hina cout << ' ' #define in(n) cin >> n #define in2(n, m) cin >> n >> m #define in3(n, m, l) cin >> n >> m >> l #define out(n) cout << n const ll mei = (ll)1e9 + 7; int main() { ll h, w, a, b; in2(h, w); vector<vector<char>> c(h, vector<char>(w)); vector<vector<ll>> d(h, vector<ll>(w, 0)); rep(i, h) { rep(j, w) in(c[i][j]); } rep(i, h) { a = 0; while (a < w) { while (c[i][a] == '#') { a++; if (a == w) break; } if (a == w) break; b = a; if (b != w - 1) { while (c[i][b + 1] == '.') { b++; if (b == w - 1) break; } } rep2(j, a, b + 1) d[i][j] += b - a + 1; a = b + 1; } } rep(i, w) { a = 0; while (a < h) { while (c[a][i] == '#') { a++; if (a == h) break; } if (a == h) break; b = a; if (b != w - 1) { while (c[b + 1][i] == '.') { b++; if (b == h - 1) break; } } rep2(j, a, b + 1) d[j][i] += b - a + 1; a = b + 1; } } a = 0; rep(i, h) { rep(j, w) a = max(a, d[i][j]); } out(a - 1); memi; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++) #define memi cout << endl #define kono(n) cout << fixed << setprecision(n) #define all(c) (c).begin(), (c).end() #define pb push_back #define hina cout << ' ' #define in(n) cin >> n #define in2(n, m) cin >> n >> m #define in3(n, m, l) cin >> n >> m >> l #define out(n) cout << n const ll mei = (ll)1e9 + 7; int main() { ll h, w, a, b; in2(h, w); vector<vector<char>> c(h, vector<char>(w)); vector<vector<ll>> d(h, vector<ll>(w, 0)); rep(i, h) { rep(j, w) in(c[i][j]); } rep(i, h) { a = 0; while (a < w) { while (c[i][a] == '#') { a++; if (a == w) break; } if (a == w) break; b = a; if (b != w - 1) { while (c[i][b + 1] == '.') { b++; if (b == w - 1) break; } } rep2(j, a, b + 1) d[i][j] += b - a + 1; a = b + 1; } } rep(i, w) { a = 0; while (a < h) { while (c[a][i] == '#') { a++; if (a == h) break; } if (a == h) break; b = a; if (b != h - 1) { while (c[b + 1][i] == '.') { b++; if (b == h - 1) break; } } rep2(j, a, b + 1) d[j][i] += b - a + 1; a = b + 1; } } a = 0; rep(i, h) { rep(j, w) a = max(a, d[i][j]); } out(a - 1); memi; }
replace
55
56
55
56
-11
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; int a[2003][2003]; rep(i, h) { string s; cin >> s; rep(j, w) { if (s[j] == '#') a[i][j] = 0; else a[i][j] = 1; } } int ans = 0; int cc = 1; int tt = 0; rep(i, h) rep(j, w) { int tmp = 0; if (a[i][j] == 1) { ++tmp; cc = 1; while (a[i - cc][j] == 1 && i - cc >= 0) { ++tmp; ++cc; } cc = 1; while (a[i + cc][j] == 1 && i + cc <= h - 1) { ++tmp; ++cc; } cc = 1; while (a[i][j - cc] == 1 && j - cc >= 0) { ++tmp; ++cc; } cc = 1; while (a[i][j + cc] == 1 && j + cc <= w - 1) { ++tmp; ++cc; } } ans = max(ans, tmp); ++tt; if (ans >= 1960 && tt >= 1000000) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; int a[2003][2003]; rep(i, h) { string s; cin >> s; rep(j, w) { if (s[j] == '#') a[i][j] = 0; else a[i][j] = 1; } } int ans = 0; int cc = 1; int tt = 0; rep(i, h) rep(j, w) { int tmp = 0; if (a[i][j] == 1) { ++tmp; cc = 1; while (a[i - cc][j] == 1 && i - cc >= 0) { ++tmp; ++cc; } cc = 1; while (a[i + cc][j] == 1 && i + cc <= h - 1) { ++tmp; ++cc; } cc = 1; while (a[i][j - cc] == 1 && j - cc >= 0) { ++tmp; ++cc; } cc = 1; while (a[i][j + cc] == 1 && j + cc <= w - 1) { ++tmp; ++cc; } } ans = max(ans, tmp); ++tt; if (ans >= 1960 && tt >= 100000) break; } cout << ans << endl; return 0; }
replace
49
50
49
50
TLE
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main() { int h, w, f, s, k, ans = 0; cin >> h >> w; char a[h][w]; int b[h][w]; fill((int *)b, (int *)b[h], 0); rep(i, h) scanf("%s", a[i]); rep(i, h) { f = -1; s = 0; rep(j, w) { if (a[i][j] == '.') { if (b[i][j] == 0) { k = i; while (a[k][j] == '.' && k < h) { k++; } for (int l = i; l < k; l++) { b[l][j] = k - i; } } if (f < j) { k = j; while (a[i][k] == '.' && k < w) { k++; } f = k; s = k - j; } ans = max(ans, b[i][j] + s); } } } cout << ans - 1; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main() { int h, w, f, s, k, ans = 0; cin >> h >> w; char a[h + 10][w + 10]; int b[h][w]; fill((int *)b, (int *)b[h], 0); rep(i, h) scanf("%s", a[i]); rep(i, h) { f = -1; s = 0; rep(j, w) { if (a[i][j] == '.') { if (b[i][j] == 0) { k = i; while (a[k][j] == '.' && k < h) { k++; } for (int l = i; l < k; l++) { b[l][j] = k - i; } } if (f < j) { k = j; while (a[i][k] == '.' && k < w) { k++; } f = k; s = k - j; } ans = max(ans, b[i][j] + s); } } } cout << ans - 1; }
replace
6
7
6
7
0
p03014
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep2(i, a, b) for (int i = (a)-1; i >= b; i--) #define chmin(a, b) (a) = min((a), (b)); #define chmax(a, b) (a) = max((a), (b)); #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define printV(v) \ cerr << (#v) << ":"; \ for (auto(x) : (v)) { \ cerr << " " << (x); \ } \ cerr << endl; #define printVS(vs) \ cerr << (#vs) << ":" << endl; \ for (auto(s) : (vs)) { \ cerr << (s) << endl; \ } #define printVV(vv) \ cerr << (#vv) << ":" << endl; \ for (auto(v) : (vv)) { \ for (auto(x) : (v)) { \ cerr << " " << (x); \ } \ cerr << endl; \ } #define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl; #define printVP(vp) \ cerr << (#vp) << ":" << endl; \ for (auto(p) : (vp)) { \ cerr << (p).first << " " << (p).second << endl; \ } inline void output() { cerr << endl; } template <typename First, typename... Rest> inline void output(const First &first, const Rest &...rest) { cerr << first << " "; output(rest...); } using ll = long long; using Pii = pair<int, int>; using TUPLE = tuple<int, int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; const int inf = 1ll << 60; const int mod = 1e9 + 7; using Graph = vector<vector<int>>; int d[2000][2000][4]; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int h, w; cin >> h >> w; int H = h + 2; int W = w + 2; vector<string> s(H); s[0] = string(W, '#'); rep(i, h) { int r = i + 1; cin >> s[r]; s[r] = '#' + s[r] + '#'; } s[H - 1] = string(W, '#'); rep(r, H) { rep(c, W) { if (s[r][c] == '#') { d[r][c][0] = -1; } else { d[r][c][0] = d[r][c - 1][0] + 1; } } } rep(r, H) { rrep(c, W) { if (s[r][c] == '#') { d[r][c][1] = -1; } else { d[r][c][1] = d[r][c + 1][1] + 1; } } } rep(c, W) { rep(r, H) { if (s[r][c] == '#') { d[r][c][2] = -1; } else { d[r][c][2] = d[r - 1][c][2] + 1; } } } rep(c, W) { rrep(r, H) { if (s[r][c] == '#') { d[r][c][3] = -1; } else { d[r][c][3] = d[r + 1][c][3] + 1; } } } int ma = 0; rep(r, H) { rep(c, W) { if (s[r][c] == '.') { chmax(ma, d[r][c][0] + d[r][c][1] + d[r][c][2] + d[r][c][3] + 1); } } } cout << ma << endl; }
#include "bits/stdc++.h" using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep2(i, a, b) for (int i = (a)-1; i >= b; i--) #define chmin(a, b) (a) = min((a), (b)); #define chmax(a, b) (a) = max((a), (b)); #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define printV(v) \ cerr << (#v) << ":"; \ for (auto(x) : (v)) { \ cerr << " " << (x); \ } \ cerr << endl; #define printVS(vs) \ cerr << (#vs) << ":" << endl; \ for (auto(s) : (vs)) { \ cerr << (s) << endl; \ } #define printVV(vv) \ cerr << (#vv) << ":" << endl; \ for (auto(v) : (vv)) { \ for (auto(x) : (v)) { \ cerr << " " << (x); \ } \ cerr << endl; \ } #define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl; #define printVP(vp) \ cerr << (#vp) << ":" << endl; \ for (auto(p) : (vp)) { \ cerr << (p).first << " " << (p).second << endl; \ } inline void output() { cerr << endl; } template <typename First, typename... Rest> inline void output(const First &first, const Rest &...rest) { cerr << first << " "; output(rest...); } using ll = long long; using Pii = pair<int, int>; using TUPLE = tuple<int, int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; const int inf = 1ll << 60; const int mod = 1e9 + 7; using Graph = vector<vector<int>>; int d[2002][2002][4]; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int h, w; cin >> h >> w; int H = h + 2; int W = w + 2; vector<string> s(H); s[0] = string(W, '#'); rep(i, h) { int r = i + 1; cin >> s[r]; s[r] = '#' + s[r] + '#'; } s[H - 1] = string(W, '#'); rep(r, H) { rep(c, W) { if (s[r][c] == '#') { d[r][c][0] = -1; } else { d[r][c][0] = d[r][c - 1][0] + 1; } } } rep(r, H) { rrep(c, W) { if (s[r][c] == '#') { d[r][c][1] = -1; } else { d[r][c][1] = d[r][c + 1][1] + 1; } } } rep(c, W) { rep(r, H) { if (s[r][c] == '#') { d[r][c][2] = -1; } else { d[r][c][2] = d[r - 1][c][2] + 1; } } } rep(c, W) { rrep(r, H) { if (s[r][c] == '#') { d[r][c][3] = -1; } else { d[r][c][3] = d[r + 1][c][3] + 1; } } } int ma = 0; rep(r, H) { rep(c, W) { if (s[r][c] == '.') { chmax(ma, d[r][c][0] + d[r][c][1] + d[r][c][2] + d[r][c][3] + 1); } } } cout << ma << endl; }
replace
55
56
55
56
-11
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 // 10^9+7 #define INF 99999999999 // 10^12-1 #define dev 998244353 // tenka1 #define P pair<int, int> #define F first #define S second int w, h, ans = 0; char c[4000][4000]; int l[4000][4000], r[4000][4000]; int u[4000][4000], d[4000][4000]; signed main() { cin >> h >> w; rep(i, h) { rep(j, w) { cin >> c[i][j]; } } rep(i, h) { rep(j, w) { if (c[i][j] == '#') continue; int x = i; while (x >= 0 && c[x][j] == '.') { u[i][j]++; x--; } x = i; while (x < h && c[x][j] == '.') { d[i][j]++; x++; } int y = j; while (y >= 0 && c[i][y] == '.') { l[i][j]++; y--; } y = j; while (y < w && c[i][y] == '.') { r[i][j]++; y++; } } } rep(i, h) { rep(j, w) { ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 // 10^9+7 #define INF 99999999999 // 10^12-1 #define dev 998244353 // tenka1 #define P pair<int, int> #define F first #define S second int w, h, ans = 0; char c[4000][4000]; int l[4000][4000], r[4000][4000]; int u[4000][4000], d[4000][4000]; signed main() { cin >> h >> w; rep(i, h) { rep(j, w) { cin >> c[i][j]; } } rep(i, h) { rep(j, w) { if (c[i][j] == '#') continue; if (j == 0) l[i][j] = 1; else l[i][j] = l[i][j - 1] + 1; } } rep(i, h) { for (int j = w - 1; j >= 0; j--) { if (c[i][j] == '#') continue; if (j == w - 1) r[i][j] = 1; else r[i][j] = r[i][j + 1] + 1; } } rep(i, w) { rep(j, h) { if (c[j][i] == '#') continue; if (j == 0) u[j][i] = 1; else u[j][i] = u[j - 1][i] + 1; } } rep(i, w) { for (int j = h - 1; j >= 0; j--) { if (c[j][i] == '#') continue; if (j == h - 1) d[j][i] = 1; else d[j][i] = d[j + 1][i] + 1; } } rep(i, h) { rep(j, w) { ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3); } } cout << ans << endl; return 0; }
replace
24
44
24
58
TLE
p03014
Python
Runtime Error
import sys import numpy as np def read(): return sys.stdin.readline().rstrip() def main(): h, w = map(int, read().split()) s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int) left = s.copy() right = s.copy up = s.copy down = s.copy for i in range(w - 1): left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1] right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2] for i in range(h - 1): up[i + 1] = (up[i] + 1) * s[i + 1] down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2] print((left + right + up + down).max() - 3) if __name__ == "__main__": main()
import sys import numpy as np def read(): return sys.stdin.readline().rstrip() def main(): h, w = map(int, read().split()) s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int) left = s.copy() right = s.copy() up = s.copy() down = s.copy() for i in range(w - 1): left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1] right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2] for i in range(h - 1): up[i + 1] = (up[i] + 1) * s[i + 1] down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2] print((left + right + up + down).max() - 3) if __name__ == "__main__": main()
replace
12
15
12
15
TLE
p03014
Python
Runtime Error
#!/usr/bin/env python3 import sys try: from typing import List except ImportError: pass def solve(H: int, W: int, S: "List[str]"): d = [[0] * W for _ in range(H)] for y in range(H): x = 0 while x < W: while x < W and S[y][x] == "#": x += 1 xstt = x while x < W and S[y][x] == ".": x += 1 xend = x for x2 in range(xstt, xend): d[y][x2] += xend - xstt for x in range(H): y = 0 while y < H: while y < H and S[y][x] == "#": y += 1 ystt = y while y < H and S[y][x] == ".": y += 1 yend = y for y2 in range(ystt, yend): d[y2][x] += yend - ystt print(max(max(r) for r in d) - 1) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int S = [next(tokens) for _ in range(H)] # type: "List[str]" solve(H, W, S) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys try: from typing import List except ImportError: pass def solve(H: int, W: int, S: "List[str]"): d = [[0] * W for _ in range(H)] for y in range(H): x = 0 while x < W: while x < W and S[y][x] == "#": x += 1 xstt = x while x < W and S[y][x] == ".": x += 1 xend = x for x2 in range(xstt, xend): d[y][x2] += xend - xstt for x in range(W): y = 0 while y < H: while y < H and S[y][x] == "#": y += 1 ystt = y while y < H and S[y][x] == ".": y += 1 yend = y for y2 in range(ystt, yend): d[y2][x] += yend - ystt print(max(max(r) for r in d) - 1) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int S = [next(tokens) for _ in range(H)] # type: "List[str]" solve(H, W, S) if __name__ == "__main__": main()
replace
22
23
22
23
0
p03014
Python
Time Limit Exceeded
H, W = map(int, input().split()) MAP = [[] for _ in range(H)] L = [[[] for h in range(W)] for _ in range(H)] R = [[[] for h in range(W)] for _ in range(H)] D = [[[] for h in range(W)] for _ in range(H)] U = [[[] for h in range(W)] for _ in range(H)] for i in range(H): MAP[i] = list(input()) for i in range(H): for j in range(W): if MAP[i][j] == "#": L[i][j] = 0 elif j == 0: L[i][j] = 1 else: L[i][j] = L[i][j - 1] + 1 if MAP[i][W - j - 1] == "#": R[i][W - j - 1] = 0 elif j == 0: R[i][W - j - 1] = 1 else: R[i][W - j - 1] = R[i][W - j] + 1 for j in range(W): for i in range(H): if MAP[i][j] == "#": U[i][j] = 0 elif i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 if MAP[H - i - 1][j] == "#": D[H - i - 1][j] = 0 elif i == 0: D[H - i - 1][j] = 1 else: D[H - i - 1][j] = D[H - i][j] + 1 result = 0 for i in range(H): for j in range(W): result = max(result, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3) print(result)
H, W = map(int, input().split()) MAP = [list(input()) for _ in range(H)] L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] for i in range(H): for j in range(W): if MAP[i][j] == "#": L[i][j] = 0 elif j == 0: L[i][j] = 1 else: L[i][j] = L[i][j - 1] + 1 if MAP[i][W - j - 1] == "#": R[i][W - j - 1] = 0 elif j == 0: R[i][W - j - 1] = 1 else: R[i][W - j - 1] = R[i][W - j] + 1 for j in range(W): for i in range(H): if MAP[i][j] == "#": U[i][j] = 0 elif i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 if MAP[H - i - 1][j] == "#": D[H - i - 1][j] = 0 elif i == 0: D[H - i - 1][j] = 1 else: D[H - i - 1][j] = D[H - i][j] + 1 result = 0 for i in range(H): for j in range(W): result = max(result, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3) print(result)
replace
1
9
1
6
TLE
p03014
Python
Runtime Error
from collections import defaultdict H, W = map(int, input().split()) mass = list() for i in range(H): mass.append(input()) values_col = defaultdict(int) values_row = defaultdict(int) ind_row = [[0 for i in range(H)] for j in range(W)] ind_col = [[0 for i in range(H)] for j in range(W)] ind = 0 for i, m_row in enumerate(mass): ind += 1 for j, chr in enumerate(mass[i]): if chr == "#": ind += 1 else: values_row[ind] += 1 ind_row[i][j] = ind # print('ROW') # for i in range(H): # for j in range(W): # print(values_row[ind_row[i][j]], end=' ') # print() ind = 0 for j in range(W): ind += 1 for i in range(H): chr = mass[i][j] if chr == "#": ind += 1 else: values_col[ind] += 1 ind_col[i][j] = ind # print('COL') # for i in range(H): # for j in range(W): # print(values_col[ind_col[i][j]], end=' ') # print() ans = 0 for i in range(H): for j in range(W): ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1) print(ans)
from collections import defaultdict H, W = map(int, input().split()) mass = list() for i in range(H): mass.append(input()) values_col = defaultdict(int) values_row = defaultdict(int) ind_row = [[0 for i in range(W)] for j in range(H)] ind_col = [[0 for i in range(W)] for j in range(H)] ind = 0 for i, m_row in enumerate(mass): ind += 1 for j, chr in enumerate(mass[i]): if chr == "#": ind += 1 else: values_row[ind] += 1 ind_row[i][j] = ind # print('ROW') # for i in range(H): # for j in range(W): # print(values_row[ind_row[i][j]], end=' ') # print() ind = 0 for j in range(W): ind += 1 for i in range(H): chr = mass[i][j] if chr == "#": ind += 1 else: values_col[ind] += 1 ind_col[i][j] = ind # print('COL') # for i in range(H): # for j in range(W): # print(values_col[ind_col[i][j]], end=' ') # print() ans = 0 for i in range(H): for j in range(W): ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1) print(ans)
replace
11
13
11
13
IndexError: list assignment index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03014/Python/s136781133.py", line 23, in <module> ind_row[i][j] = ind IndexError: list assignment index out of range
p03014
Python
Time Limit Exceeded
import numpy as np h, w = map(int, input().split()) grid = [[False for j in range(w)] for i in range(h)] for i in range(h): s = input() for j in range(w): if s[j] == ".": grid[i][j] = 1 else: grid[i][j] = 0 grid = np.array(grid) L = np.zeros((h, w), dtype=int) R = np.zeros((h, w), dtype=int) U = np.zeros((h, w), dtype=int) D = np.zeros((h, w), dtype=int) for j in range(w): if j == 0: L[:, j] = grid[:, j] else: L[:, j] = (L[:, j - 1] + 1) * grid[:, j] for j in range(w - 1, -1, -1): if j >= w - 1: R[:, j] = grid[:, j] else: R[:, j] = (R[:, j + 1] + 1) * grid[:, j] for i in range(h): if i <= 0: U[i, :] = grid[i, :] else: U[i, :] = (U[i - 1, :] + 1) * grid[i, :] for i in range(h - 1, -1, -1): if i >= h - 1: D[i, :] = grid[i, :] else: D[i, :] = (D[i + 1, :] + 1) * grid[i, :] nums = [] for i in range(h): for j in range(w): nums.append(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3) print(np.max(L + R + U + D - 3))
import numpy as np h, w = map(int, input().split()) grid = [[False for j in range(w)] for i in range(h)] for i in range(h): s = input() for j in range(w): if s[j] == ".": grid[i][j] = 1 else: grid[i][j] = 0 grid = np.array(grid) L = np.zeros((h, w), dtype=int) R = np.zeros((h, w), dtype=int) U = np.zeros((h, w), dtype=int) D = np.zeros((h, w), dtype=int) for j in range(w): if j == 0: L[:, j] = grid[:, j] else: L[:, j] = (L[:, j - 1] + 1) * grid[:, j] for j in range(w - 1, -1, -1): if j >= w - 1: R[:, j] = grid[:, j] else: R[:, j] = (R[:, j + 1] + 1) * grid[:, j] for i in range(h): if i <= 0: U[i, :] = grid[i, :] else: U[i, :] = (U[i - 1, :] + 1) * grid[i, :] for i in range(h - 1, -1, -1): if i >= h - 1: D[i, :] = grid[i, :] else: D[i, :] = (D[i + 1, :] + 1) * grid[i, :] print(np.max(L + R + U + D - 3))
delete
46
52
46
46
TLE
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s.at(i); } vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s.at(i).at(j) == '#') { continue; } if (done.at(j)) { continue; } int l = 0; while ((j + l) < w) { if (s.at(i).at(j + l) == '#') { break; } l++; } for (int k = 0; k < l; k++) { cnt.at(i).at(j + k) += l; done.at(j + k) = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(h); for (int i = 0; i < h; i++) { if (s.at(i).at(j) == '#') { continue; } if (done.at(i)) { continue; } int l = 0; while ((i + l) < w) { if (s.at(i + l).at(j) == '#') { break; } l++; } for (int k = 0; k < l; k++) { cnt.at(i + k).at(j) += l; done.at(i + k) = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt.at(i).at(j) - 1); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s.at(i); } vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s.at(i).at(j) == '#') { continue; } if (done.at(j)) { continue; } int l = 0; while ((j + l) < w) { if (s.at(i).at(j + l) == '#') { break; } l++; } for (int k = 0; k < l; k++) { cnt.at(i).at(j + k) += l; done.at(j + k) = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(h); for (int i = 0; i < h; i++) { if (s.at(i).at(j) == '#') { continue; } if (done.at(i)) { continue; } int l = 0; while ((i + l) < h) { if (s.at(i + l).at(j) == '#') { break; } l++; } for (int k = 0; k < l; k++) { cnt.at(i + k).at(j) += l; done.at(i + k) = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt.at(i).at(j) - 1); } } cout << ans << endl; }
replace
47
48
47
48
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
p03014
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, start, end) for (int i = start; i <= end; i++) const int INF = 1001001001; using namespace std; typedef long long ll; int H, W; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #define WMAX 200 #define HMAX WMAX char s[HMAX][WMAX]; int dp[HMAX][WMAX][4]; // dp[i][j][k] (0:right 1:down 2:left 3:up) int dfs(int x, int y, int k) { if (s[y][x] == '#') return 0; if (dp[y][x][k] != -1) return dp[y][x][k]; int nx = x + dx[k]; int ny = y + dy[k]; if (0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#') { int num = dfs(nx, ny, k) + 1; dp[y][x][k] = num; return num; } dp[y][x][k] = 0; return 0; } int main() { int res = 0; cin >> H >> W; rep(i, H) cin >> s[i]; memset(dp, -1, sizeof dp); rep(y, H) { rep(x, W) { int sum = 0; rep(k, 4) { sum += dfs(x, y, k); } if (s[y][x] != '#') sum++; res = max(sum, res); // printf("%3d ", sum); } // cout << endl; } cout << res << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, start, end) for (int i = start; i <= end; i++) const int INF = 1001001001; using namespace std; typedef long long ll; int H, W; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #define WMAX 2001 #define HMAX WMAX char s[HMAX][WMAX]; int dp[HMAX][WMAX][4]; // dp[i][j][k] (0:right 1:down 2:left 3:up) int dfs(int x, int y, int k) { if (s[y][x] == '#') return 0; if (dp[y][x][k] != -1) return dp[y][x][k]; int nx = x + dx[k]; int ny = y + dy[k]; if (0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#') { int num = dfs(nx, ny, k) + 1; dp[y][x][k] = num; return num; } dp[y][x][k] = 0; return 0; } int main() { int res = 0; cin >> H >> W; rep(i, H) cin >> s[i]; memset(dp, -1, sizeof dp); rep(y, H) { rep(x, W) { int sum = 0; rep(k, 4) { sum += dfs(x, y, k); } if (s[y][x] != '#') sum++; res = max(sum, res); // printf("%3d ", sum); } // cout << endl; } cout << res << endl; }
replace
10
11
10
11
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector<vector<char>> S(H, vector<char>(W)); vector<vector<pair<int, int>>> B(H, vector<pair<int, int>>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } vector<int> c(H * W); int num = 0; int count = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { c[num] = count; count = 0; num++; } else { count++; B[i][j].first = num; } } c[num] = count; count = 0; num++; } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (S[j][i] == '#') { c[num] = count; count = 0; num++; } else { count++; B[j][i].second = num; } } c[num] = count; count = 0; num++; } int max = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int x = c[B[i][j].first] + c[B[i][j].second]; if (x > max) max = x; } } cout << max - 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector<vector<char>> S(H, vector<char>(W)); vector<vector<pair<int, int>>> B(H, vector<pair<int, int>>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } vector<int> c(H * W * 3); int num = 0; int count = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { c[num] = count; count = 0; num++; } else { count++; B[i][j].first = num; } } c[num] = count; count = 0; num++; } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (S[j][i] == '#') { c[num] = count; count = 0; num++; } else { count++; B[j][i].second = num; } } c[num] = count; count = 0; num++; } int max = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int x = c[B[i][j].first] + c[B[i][j].second]; if (x > max) max = x; } } cout << max - 1 << endl; }
replace
22
23
22
23
0
p03014
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <vector> using namespace std; int main() { int H, W, ans = 0, v[20][20] = {}, k = 0, n = 0; char masu[21][21]; cin >> H >> W; for (int i = 0; i < H; i++) { k = 0; n = 0; for (int j = 0; j < W; j++) { cin >> masu[i][j]; if (masu[i][j] == '.') k++; else { for (int l = 0; l < k; l++) { v[i][n] += k; n++; } n = n + 1; k = 0; } } if (masu[i][W - 1] == '.') { for (int l = 0; l < k; l++) { v[i][n] += k; n++; } n = n + 1; k = 0; } } for (int i = 0; i < W; i++) { k = 0; n = 0; for (int j = 0; j < H; j++) { if (masu[j][i] == '.') k++; else { for (int l = 0; l < k; l++) { v[n][i] += k; n++; } n = n + 1; k = 0; } } if (masu[H - 1][i] == '.') { for (int l = 0; l < k; l++) { v[n][i] += k; n++; } k = 0; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(v[i][j], ans); // cout << v[i][j] << " "; } // cout << endl; } cout << ans - 1; }
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <vector> using namespace std; int main() { int H, W, ans = 0, v[2001][2001] = {}, k = 0, n = 0; char masu[2001][2001]; cin >> H >> W; for (int i = 0; i < H; i++) { k = 0; n = 0; for (int j = 0; j < W; j++) { cin >> masu[i][j]; if (masu[i][j] == '.') k++; else { for (int l = 0; l < k; l++) { v[i][n] += k; n++; } n = n + 1; k = 0; } } if (masu[i][W - 1] == '.') { for (int l = 0; l < k; l++) { v[i][n] += k; n++; } n = n + 1; k = 0; } } for (int i = 0; i < W; i++) { k = 0; n = 0; for (int j = 0; j < H; j++) { if (masu[j][i] == '.') k++; else { for (int l = 0; l < k; l++) { v[n][i] += k; n++; } n = n + 1; k = 0; } } if (masu[H - 1][i] == '.') { for (int l = 0; l < k; l++) { v[n][i] += k; n++; } k = 0; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(v[i][j], ans); // cout << v[i][j] << " "; } // cout << endl; } cout << ans - 1; }
replace
10
12
10
12
0
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, m; char a[2005][2005]; int ans = 0; int main() { scanf("%d%d", &n, &m); int ma = n + m - 1; for (int i = 0; i < n; i++) scanf("%s", a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int s = 1; if (a[i][j] == '.') { for (int k = j - 1; k >= 0; k--) if (a[i][k] == '.') s++; else break; for (int k = j + 1; k < m; k++) if (a[i][k] == '.') s++; else break; for (int l = i - 1; l >= 0; l--) if (a[l][j] == '.') s++; else break; for (int l = i + 1; l < n; l++) if (a[l][j] == '.') s++; else break; ans = max(s, ans); } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; char a[2005][2005]; int ans = 0; int main() { scanf("%d%d", &n, &m); int ma = n + m - 1; for (int i = 0; i < n; i++) scanf("%s", a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int s = 1; if (a[i][j] == '.') { for (int k = j - 1; k >= 0; k--) if (a[i][k] == '.') s++; else break; for (int k = j + 1; k < m; k++) if (a[i][k] == '.') s++; else break; for (int l = i - 1; l >= 0; l--) if (a[l][j] == '.') s++; else break; for (int l = i + 1; l < n; l++) if (a[l][j] == '.') s++; else break; ans = max(s, ans); if (ans == ma) break; } } printf("%d\n", ans); return 0; }
insert
38
38
38
40
TLE
p03014
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } // 各行(列)に何個障害物があるかを累積和で記録する vector<vector<int>> cumh(h, vector<int>(w, 0)); vector<vector<int>> cumw(w, vector<int>(h, 0)); for (int i = 0; i < h; i++) { if (s[i][0] == '#') cumh[i][0] = 1; for (int j = 1; j < w; j++) { if (s[i][j] == '#') { cumh[i][j] = cumh[i][j - 1] + 1; } else { cumh[i][j] = cumh[i][j - 1]; } } } for (int i = 0; i < w; i++) { if (s[0][i] == '#') cumw[i][0] = 1; for (int j = 1; j < h; j++) { if (s[j][i] == '#') { cumw[i][j] = cumw[i][j - 1] + 1; } else { cumw[i][j] = cumw[i][j - 1]; } } } // 各マスにランプを置いたときに照らせるマスの個数を計算 // それぞれの方向で累積和が変化する場所を二分探索で計算 // 比較関数 auto lower = [](int l, int r, vector<int> a, int target) { while (l < r - 1) { int m = (r + l) / 2; if (a[m] < target) { l = m; } else { r = m; } } return r; }; int result = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // 右方向 int target_right = upper_bound(cumh[i].begin(), cumh[i].end(), cumh[i][j]) - cumh[i].begin(); // 左方向 int target_left = lower(-1, w - 1, cumh[i], cumh[i][j]); // 上方向 int target_up = lower(-1, h - 1, cumw[j], cumw[j][i]); // 下方向 int target_down = upper_bound(cumw[j].begin(), cumw[j].end(), cumw[j][i]) - cumw[j].begin(); // 変化するところは障害物があるところ int total = 0; if (s[i][j] != '#') { if (s[target_up][j] == '#') { total += (j - target_up - 1); } else { total += (j - target_up); } if (s[i][target_left] == '#') { total += (i - target_left - 1); } else { total += (i - target_left); } total += (target_right - j - 1) + (target_down - i - 1) + 1; } result = max(result, total); } } cout << result << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } // 各行(列)に何個障害物があるかを累積和で記録する vector<vector<int>> cumh(h, vector<int>(w, 0)); vector<vector<int>> cumw(w, vector<int>(h, 0)); for (int i = 0; i < h; i++) { if (s[i][0] == '#') cumh[i][0] = 1; for (int j = 1; j < w; j++) { if (s[i][j] == '#') { cumh[i][j] = cumh[i][j - 1] + 1; } else { cumh[i][j] = cumh[i][j - 1]; } } } for (int i = 0; i < w; i++) { if (s[0][i] == '#') cumw[i][0] = 1; for (int j = 1; j < h; j++) { if (s[j][i] == '#') { cumw[i][j] = cumw[i][j - 1] + 1; } else { cumw[i][j] = cumw[i][j - 1]; } } } // 各マスにランプを置いたときに照らせるマスの個数を計算 // それぞれの方向で累積和が変化する場所を二分探索で計算 // 比較関数 auto lower = [](int l, int r, vector<int> &a, int target) { while (l < r - 1) { int m = (r + l) / 2; if (a[m] < target) { l = m; } else { r = m; } } return r; }; int result = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // 右方向 int target_right = upper_bound(cumh[i].begin(), cumh[i].end(), cumh[i][j]) - cumh[i].begin(); // 左方向 int target_left = lower(-1, w - 1, cumh[i], cumh[i][j]); // 上方向 int target_up = lower(-1, h - 1, cumw[j], cumw[j][i]); // 下方向 int target_down = upper_bound(cumw[j].begin(), cumw[j].end(), cumw[j][i]) - cumw[j].begin(); // 変化するところは障害物があるところ int total = 0; if (s[i][j] != '#') { if (s[target_up][j] == '#') { total += (j - target_up - 1); } else { total += (j - target_up); } if (s[i][target_left] == '#') { total += (i - target_left - 1); } else { total += (i - target_left); } total += (target_right - j - 1) + (target_down - i - 1) + 1; } result = max(result, total); } } cout << result << endl; }
replace
42
43
42
43
TLE
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; char S[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } int maxcnt = 0; int temp; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') continue; temp = 1; for (int ii = i - 1; ii >= 0; ii--) { if (S[ii][j] == '#') break; temp++; } for (int ii = i + 1; ii <= H - 1; ii++) { if (S[ii][j] == '#') break; temp++; } for (int jj = j - 1; jj >= 0; jj--) { if (S[i][jj] == '#') break; temp++; } for (int jj = j + 1; jj <= W - 1; jj++) { if (S[i][jj] == '#') break; temp++; } maxcnt = max(maxcnt, temp); } } cout << maxcnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; char S[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } int maxcnt = 0; int temp; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') continue; temp = 1; for (int ii = i - 1; ii >= 0; ii--) { if (S[ii][j] == '#') break; temp++; } for (int ii = i + 1; ii <= H - 1; ii++) { if (S[ii][j] == '#') break; temp++; } for (int jj = j - 1; jj >= 0; jj--) { if (S[i][jj] == '#') break; temp++; } for (int jj = j + 1; jj <= W - 1; jj++) { if (S[i][jj] == '#') break; temp++; } maxcnt = max(maxcnt, temp); if (maxcnt == W + H - 1) break; } } cout << maxcnt << endl; }
insert
42
42
42
44
TLE
p03014
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...); } class UnionFind { private: ::std::vector<int_fast32_t> par, edge; size_t n; public: UnionFind() {} UnionFind(size_t n) : n(n) { par.resize(n, -1); edge.resize(n, 0); } uint_fast32_t find(uint_fast32_t x) { return par[x] < 0 ? x : par[x] = find(par[x]); } size_t size(uint_fast32_t x) { return -par[find(x)]; } bool unite(uint_fast32_t x, uint_fast32_t y) { x = find(x); y = find(y); edge[x] += 1; if (x == y) return false; if (size(x) < size(y)) std::swap(x, y); par[x] += par[y]; edge[x] += edge[y]; par[y] = x; return true; } bool same(uint_fast32_t x, uint_fast32_t y) { return find(x) == find(y); } size_t esize(uint_fast32_t x) { return edge[find(x)]; } }; template <::std::uint_fast64_t mod> class ModInt { private: using value_type = ::std::uint_fast64_t; value_type n; public: ModInt() : n(0) {} ModInt(value_type n_) : n(n_ % mod) {} ModInt(const ModInt &m) : n(m.n) {} template <typename T> explicit operator T() const { return static_cast<T>(n); } value_type get() const { return n; } friend ::std::ostream &operator<<(::std::ostream &os, const ModInt<mod> &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, ModInt<mod> &a) { value_type x; is >> x; a = ModInt<mod>(x); return is; } bool operator==(const ModInt &m) const { return n == m.n; } bool operator!=(const ModInt &m) const { return n != m.n; } ModInt &operator*=(const ModInt &m) { n = n * m.n % mod; return *this; } ModInt pow(value_type b) const { ModInt ans = 1, m = ModInt(*this); while (b) { if (b & 1) ans *= m; m *= m; b >>= 1; } return ans; } ModInt inv() const { return (*this).pow(mod - 2); } ModInt &operator+=(const ModInt &m) { n += m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator-=(const ModInt &m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator/=(const ModInt &m) { *this *= m.inv(); return *this; } ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; } ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; } ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; } ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; } ModInt &operator++() { n += 1; return *this; } ModInt &operator--() { n -= 1; return *this; } ModInt operator++(int) { ModInt old(n); n += 1; return old; } ModInt operator--(int) { ModInt old(n); n -= 1; return old; } ModInt operator-() const { return ModInt(mod - n); } }; constexpr int64 mod = 1e9 + 7; using Mint = ModInt<mod>; int64 dx[4] = {-1, 0, 0, 1}; int64 dy[4] = {0, -1, 1, 0}; auto d = make_v<int64>(1, 1, 1); vector<string> s; int64 H, W; bool in(int64 y, int64 x) { return 0 <= y && y < H && 0 <= x && x < W && s[y][x] != '#'; } int64 calc(int64 y, int64 x) { int64 sum = 0; REP(dd, 4) { int64 cnt = 0; int64 ny = y, nx = x; while (in(ny, nx)) { if (d[dd][ny][nx] != -1) { cnt += d[dd][ny][nx]; break; } ny += dy[dd]; nx += dx[dd]; cnt++; } ny = y; nx = x; while (in(ny, nx)) { if (d[dd][ny][nx] != -1) break; d[dd][ny][nx] = cnt - abs(ny - y) - abs(nx - x); } sum += d[dd][y][x]; } return sum; } int main(void) { cin >> H >> W; d = make_v<int64>(4, H, W); fill_v<int64>(d, -1); s = vector<string>(H); REP(i, H) cin >> s[i]; int64 res = 0; REP(i, H) { REP(j, W) { res = max(res, calc(i, j) - 3); } } 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...); } class UnionFind { private: ::std::vector<int_fast32_t> par, edge; size_t n; public: UnionFind() {} UnionFind(size_t n) : n(n) { par.resize(n, -1); edge.resize(n, 0); } uint_fast32_t find(uint_fast32_t x) { return par[x] < 0 ? x : par[x] = find(par[x]); } size_t size(uint_fast32_t x) { return -par[find(x)]; } bool unite(uint_fast32_t x, uint_fast32_t y) { x = find(x); y = find(y); edge[x] += 1; if (x == y) return false; if (size(x) < size(y)) std::swap(x, y); par[x] += par[y]; edge[x] += edge[y]; par[y] = x; return true; } bool same(uint_fast32_t x, uint_fast32_t y) { return find(x) == find(y); } size_t esize(uint_fast32_t x) { return edge[find(x)]; } }; template <::std::uint_fast64_t mod> class ModInt { private: using value_type = ::std::uint_fast64_t; value_type n; public: ModInt() : n(0) {} ModInt(value_type n_) : n(n_ % mod) {} ModInt(const ModInt &m) : n(m.n) {} template <typename T> explicit operator T() const { return static_cast<T>(n); } value_type get() const { return n; } friend ::std::ostream &operator<<(::std::ostream &os, const ModInt<mod> &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, ModInt<mod> &a) { value_type x; is >> x; a = ModInt<mod>(x); return is; } bool operator==(const ModInt &m) const { return n == m.n; } bool operator!=(const ModInt &m) const { return n != m.n; } ModInt &operator*=(const ModInt &m) { n = n * m.n % mod; return *this; } ModInt pow(value_type b) const { ModInt ans = 1, m = ModInt(*this); while (b) { if (b & 1) ans *= m; m *= m; b >>= 1; } return ans; } ModInt inv() const { return (*this).pow(mod - 2); } ModInt &operator+=(const ModInt &m) { n += m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator-=(const ModInt &m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator/=(const ModInt &m) { *this *= m.inv(); return *this; } ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; } ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; } ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; } ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; } ModInt &operator++() { n += 1; return *this; } ModInt &operator--() { n -= 1; return *this; } ModInt operator++(int) { ModInt old(n); n += 1; return old; } ModInt operator--(int) { ModInt old(n); n -= 1; return old; } ModInt operator-() const { return ModInt(mod - n); } }; constexpr int64 mod = 1e9 + 7; using Mint = ModInt<mod>; int64 dx[4] = {-1, 0, 0, 1}; int64 dy[4] = {0, -1, 1, 0}; auto d = make_v<int64>(1, 1, 1); vector<string> s; int64 H, W; bool in(int64 y, int64 x) { return 0 <= y && y < H && 0 <= x && x < W && s[y][x] != '#'; } int64 calc(int64 y, int64 x) { int64 sum = 0; REP(dd, 4) { int64 cnt = 0; int64 ny = y, nx = x; while (in(ny, nx)) { if (d[dd][ny][nx] != -1) { cnt += d[dd][ny][nx]; break; } ny += dy[dd]; nx += dx[dd]; cnt++; } ny = y; nx = x; while (in(ny, nx)) { if (d[dd][ny][nx] != -1) break; d[dd][ny][nx] = cnt - abs(ny - y) - abs(nx - x); ny += dy[dd]; nx += dx[dd]; } sum += d[dd][y][x]; } return sum; } int main(void) { cin >> H >> W; d = make_v<int64>(4, H, W); fill_v<int64>(d, -1); s = vector<string>(H); REP(i, H) cin >> s[i]; int64 res = 0; REP(i, H) { REP(j, W) { res = max(res, calc(i, j) - 3); } } cout << res << endl; }
insert
200
200
200
202
TLE
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll, ll> P; #define rep(i, a, b) for (ll i = a; i < b; i++) const int max_n = 1e5; const ll mod = 1e9 + 7; typedef long double ld; int main() { int h, w; cin >> h >> w; string s[h]; rep(i, 0, h) cin >> s[i]; int d[2005][2005]; rep(i, 0, h) rep(j, 0, w) d[i][j] = 0; int ma = 0; rep(i, 0, h) rep(j, 0, w) { if ((j - 1 < 0 || s[i][j - 1] == '#') && s[i][j] == '.') { int k = j; while (s[i][j] == s[i][k] && k < w) k++; rep(t, j, k) { d[i][t] += k - j - 1; ma = max(ma, d[i][t]); } } if ((i - 1 < 0 || s[i - 1][j] == '#') && s[i][j] == '.') { int k = i; while (s[i][j] == s[k][j] && k < h) k++; rep(t, i, k) { d[t][j] += k - i; ma = max(ma, d[t][j]); } } } cout << ma << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll, ll> P; #define rep(i, a, b) for (ll i = a; i < b; i++) const int max_n = 1e5; const ll mod = 1e9 + 7; typedef long double ld; int main() { int h, w; cin >> h >> w; string s[h + 5]; rep(i, 0, h) cin >> s[i]; int d[2005][2005]; rep(i, 0, h) rep(j, 0, w) d[i][j] = 0; int ma = 0; rep(i, 0, h) rep(j, 0, w) { if ((j - 1 < 0 || s[i][j - 1] == '#') && s[i][j] == '.') { int k = j; while (s[i][j] == s[i][k] && k < w) k++; rep(t, j, k) { d[i][t] += k - j - 1; ma = max(ma, d[i][t]); } } if ((i - 1 < 0 || s[i - 1][j] == '#') && s[i][j] == '.') { int k = i; while (s[i][j] == s[k][j] && k < h) k++; rep(t, i, k) { d[t][j] += k - i; ma = max(ma, d[t][j]); } } } cout << ma << endl; return 0; }
replace
16
17
16
17
-11
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define FOR(i, s, n) for (int i = s; i < n; i++) #define REP(n) FOR(i, 0, n) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() using INT64 = long long; using UINT64 = unsigned long long; int main(void) { IOS int h, w; cin >> h >> w; vector<string> ss(h); REP(h) cin >> ss[i]; vector<vector<int>> v(h, vector<int>(w, 0)); vector<int> lh(h, 0); // ライト縦方向 int lw; // ライト横方向 FOR(i, 0, h) { lw = 0; FOR(j, 0, w) { if (ss[i][j] == '#') { int i2 = i - 1; while (i2 >= 0 && ss[i2][j] == '.') { v[i2][j] += lh[j]; i2--; } int j2 = j - 1; while (j2 >= 0 && ss[i][j2] == '.') { v[i][j2] += lw; j2--; } lh[j] = 0; lw = 0; continue; } lh[j]++; lw++; if (j == w - 1) { int j2 = j; while (j2 >= 0 && ss[i][j2] == '.') { v[i][j2] += lw; j2--; } } if (i == h - 1) { // cerr << lh[j]; int i2 = i; while (i2 >= 0 && ss[i2][j] == '.') { v[i2][j] += lh[j]; i2--; } } } // REP(h) cerr << lh[i]; // cerr << endl; } REP(h) { // FOR(j,0,w) cerr << v[i][j] << " "; // cerr << endl; sort(RALL(v[i])); } int ans = 0; REP(h) { // FOR(j,0,w) cerr << v[i][j]; // cerr << endl; if (ans < v[i][0]) ans = v[i][0]; } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define FOR(i, s, n) for (int i = s; i < n; i++) #define REP(n) FOR(i, 0, n) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() using INT64 = long long; using UINT64 = unsigned long long; int main(void) { IOS int h, w; cin >> h >> w; vector<string> ss(h); REP(h) cin >> ss[i]; vector<vector<int>> v(h, vector<int>(w, 0)); vector<int> lh(w, 0); // ライト縦方向 int lw; // ライト横方向 FOR(i, 0, h) { lw = 0; FOR(j, 0, w) { if (ss[i][j] == '#') { int i2 = i - 1; while (i2 >= 0 && ss[i2][j] == '.') { v[i2][j] += lh[j]; i2--; } int j2 = j - 1; while (j2 >= 0 && ss[i][j2] == '.') { v[i][j2] += lw; j2--; } lh[j] = 0; lw = 0; continue; } lh[j]++; lw++; if (j == w - 1) { int j2 = j; while (j2 >= 0 && ss[i][j2] == '.') { v[i][j2] += lw; j2--; } } if (i == h - 1) { // cerr << lh[j]; int i2 = i; while (i2 >= 0 && ss[i2][j] == '.') { v[i2][j] += lh[j]; i2--; } } } // REP(h) cerr << lh[i]; // cerr << endl; } REP(h) { // FOR(j,0,w) cerr << v[i][j] << " "; // cerr << endl; sort(RALL(v[i])); } int ans = 0; REP(h) { // FOR(j,0,w) cerr << v[i][j]; // cerr << endl; if (ans < v[i][0]) ans = v[i][0]; } cout << ans - 1 << endl; return 0; }
replace
20
21
20
21
0
p03014
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); vector<vector<int>> ans_h(h, vector<int>(w, 0)); vector<vector<int>> ans_w(h, vector<int>(w, 0)); for (int i = 0; i < h; i++) { cin >> s[i]; for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; int cnt = 0; while (j + cnt < w && s[i][j + cnt] == '.') cnt++; for (int k = j; k < j + cnt; k++) ans_w[i][k] = cnt; j += cnt - 1; } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (s[j][i] == '#') continue; int cnt = 0; while (j + cnt < w && s[j + cnt][i] == '.') cnt++; for (int k = j; k < j + cnt; k++) ans_h[k][i] = cnt; j += cnt - 1; } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, ans_w[i][j] + ans_h[i][j] - 1); } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); vector<vector<int>> ans_h(h, vector<int>(w, 0)); vector<vector<int>> ans_w(h, vector<int>(w, 0)); for (int i = 0; i < h; i++) { cin >> s[i]; for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; int cnt = 0; while (j + cnt < w && s[i][j + cnt] == '.') cnt++; for (int k = j; k < j + cnt; k++) ans_w[i][k] = cnt; j += cnt - 1; } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (s[j][i] == '#') continue; int cnt = 0; while (j + cnt < h && s[j + cnt][i] == '.') cnt++; for (int k = j; k < j + cnt; k++) ans_h[k][i] = cnt; j += cnt - 1; } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, ans_w[i][j] + ans_h[i][j] - 1); } } cout << ans << endl; }
replace
36
37
36
37
-11
p03014
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; #define mod 1000000007 int h, w; char s[2001][2001]; int result[2001][2001][4] = {}; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int getresult(int i, int j, int k) { if (i < 0 || j < 0 || i >= h || j >= w) return 0; if (result[i][j][k] >= 0) return result[i][j][k]; if (s[i][j] == '#') return result[i][j][k] = 0; return getresult(i + dx[k], j + dy[k], k) + 1; } int main() { cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> s[i][j]; for (int k = 0; k < 4; k++) { result[i][j][k] = -1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; int nowresult = 0; for (int k = 0; k < 4; k++) { nowresult += getresult(i + dx[k], j + dy[k], k); } nowresult++; ans = max(ans, nowresult); } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; #define mod 1000000007 int h, w; char s[2001][2001]; int result[2001][2001][4] = {}; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int getresult(int i, int j, int k) { if (i < 0 || j < 0 || i >= h || j >= w) return 0; if (result[i][j][k] >= 0) return result[i][j][k]; if (s[i][j] == '#') return result[i][j][k] = 0; return result[i][j][k] = getresult(i + dx[k], j + dy[k], k) + 1; } int main() { cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> s[i][j]; for (int k = 0; k < 4; k++) { result[i][j][k] = -1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; int nowresult = 0; for (int k = 0; k < 4; k++) { nowresult += getresult(i + dx[k], j + dy[k], k); } nowresult++; ans = max(ans, nowresult); } } cout << ans << endl; }
replace
37
38
37
38
TLE
p03014
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + 1 < w) { if (s[i][j + l] == '#') break; l++; } for (int k = 0; k < l; k++) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(h); for (int i = 0; i < h; i++) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; l++; } for (int k = 0; k < l; k++) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt[i][j] - 1); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } vector<vector<int>> cnt(h, vector<int>(w)); for (int i = 0; i < h; i++) { vector<int> done(w); for (int j = 0; j < w; j++) { if (s[i][j] == '#') continue; if (done[j]) continue; int l = 0; while (j + l < w) { if (s[i][j + l] == '#') break; l++; } for (int k = 0; k < l; k++) { cnt[i][j + k] += l; done[j + k] = 1; } } } for (int j = 0; j < w; j++) { vector<int> done(h); for (int i = 0; i < h; i++) { if (s[i][j] == '#') continue; if (done[i]) continue; int l = 0; while (i + l < h) { if (s[i + l][j] == '#') break; l++; } for (int k = 0; k < l; k++) { cnt[i + k][j] += l; done[i + k] = 1; } } } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ans = max(ans, cnt[i][j] - 1); } } cout << ans << endl; return 0; }
replace
27
28
27
28
-11
p03014
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int H, W; char M[2005][2005]; bool vis[4][2005][2005]; int D[4][2005][2005]; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; inline bool val(int i, int j) { return 0 <= i && i < H && 0 <= j && j < W; } int dfs(int k, int i, int j) { if (vis[k][i][j]) return D[k][i][j]; if (M[i][j] == '#') return 0; if (!val(i, j)) return 0; int x = i + dx[k], y = j + dy[k]; return D[k][i][j] = dfs(k, x, y) + 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> H >> W; for (int i = 0; i < H; i++) { cin >> M[i]; } for (int k = 0; k < 4; k++) { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (vis[k][i][j]) continue; dfs(k, i, j); } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(ans, D[0][i][j] + D[1][i][j] + D[2][i][j] + D[3][i][j] - 3); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int H, W; char M[2005][2005]; bool vis[4][2005][2005]; int D[4][2005][2005]; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; inline bool val(int i, int j) { return 0 <= i && i < H && 0 <= j && j < W; } int dfs(int k, int i, int j) { if (vis[k][i][j]) return D[k][i][j]; if (M[i][j] == '#') return 0; if (!val(i, j)) return 0; vis[k][i][j] = true; int x = i + dx[k], y = j + dy[k]; return D[k][i][j] = dfs(k, x, y) + 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> H >> W; for (int i = 0; i < H; i++) { cin >> M[i]; } for (int k = 0; k < 4; k++) { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (vis[k][i][j]) continue; dfs(k, i, j); } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(ans, D[0][i][j] + D[1][i][j] + D[2][i][j] + D[3][i][j] - 3); } } cout << ans << endl; }
insert
22
22
22
23
TLE
p03014
C++
Runtime Error
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge { // グラフに使うヤツ ll from, to, cost; }; typedef vector<vector<edge>> G; ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } int main() { ll h, w; cin >> h >> w; string s[h]; for (ll i = 0; i < h; i++) cin >> s[i]; ll tate[h][w], yoko[h][w]; memset(tate, 0, sizeof(tate)); memset(yoko, 0, sizeof(yoko)); for (ll i = 0; i < h; i++) { ll c = 0; for (ll j = 0; j < w; j++) { if (s[i][j] == '#') { yoko[i][j] = 0; if (c != 0) { ll x = j - 1; while (s[i][x] == '.' and x >= 0) { yoko[i][x] = c; x--; } c = 0; } } else { c++; } } if (c) { ll x = w - 1; while (x >= 0 and s[i][x] == '.') { yoko[i][x] = c; x--; } } } for (ll i = 0; i < w; i++) { ll c = 0; for (ll j = 0; j < h; j++) { if (s[j][i] == '#') { tate[j][i] = 0; if (c != 0) { ll x = j - 1; while (x >= 0 and s[x][i] == '.') { tate[x][i] = c; x--; } c = 0; } } else { c++; } } if (c) { ll x = h - 1; while (s[x][i] == '.' and x >= 0) { tate[x][i] = c; x--; } } } ll ans = 0; for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) { ans = max(ans, tate[i][j] + yoko[i][j]); } } cout << ans - 1 << endl; return 0; }
#include <iostream> // #include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge { // グラフに使うヤツ ll from, to, cost; }; typedef vector<vector<edge>> G; ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } int main() { ll h, w; cin >> h >> w; string s[h]; for (ll i = 0; i < h; i++) cin >> s[i]; ll tate[h][w], yoko[h][w]; memset(tate, 0, sizeof(tate)); memset(yoko, 0, sizeof(yoko)); for (ll i = 0; i < h; i++) { ll c = 0; for (ll j = 0; j < w; j++) { if (s[i][j] == '#') { yoko[i][j] = 0; if (c != 0) { ll x = j - 1; while (s[i][x] == '.' and x >= 0) { yoko[i][x] = c; x--; } c = 0; } } else { c++; } } if (c) { ll x = w - 1; while (x >= 0 and s[i][x] == '.') { yoko[i][x] = c; x--; } } } for (ll i = 0; i < w; i++) { ll c = 0; for (ll j = 0; j < h; j++) { if (s[j][i] == '#') { tate[j][i] = 0; if (c != 0) { ll x = j - 1; while (x >= 0 and s[x][i] == '.') { tate[x][i] = c; x--; } c = 0; } } else { c++; } } if (c) { ll x = h - 1; while (s[x][i] == '.' and x >= 0) { tate[x][i] = c; x--; } } } ll ans = 0; for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) { ans = max(ans, tate[i][j] + yoko[i][j]); } } cout << ans - 1 << endl; return 0; }
replace
0
1
0
1
-11
p03014
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define pb push_back #define pf push_front #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vip vector<pair<int, int>> #define ff first #define ss second #define int long long #define SIZE 200010 #define mod 1000000007 #define BIG 998244353 #define s(t) scanf("%d", &t) #define p(t) printf("%d\n", t) #define mii map<int, int> #define MSET(table, i) memset(table, i, sizeof(table)) #define endl '\n' #define tc \ int t; \ cin >> t; \ while (t--) #define pi 3.1415926358 #define print(x) \ for (auto el : x) \ cout << el << " "; \ cout << endl #define bits(x) __builtin_popcount(x) #define minimum(a, n) min_element(a, a + n) - a #define maximum(a, n) max_element(a, a + n) - a #define pqbig priority_queue<int> #define pqsmall priority_queue<int, vector<int>, greater<int>> #define all(v) v.begin(), v.end() #define sitr set<int>::iterator #define mitr map<int, int>::iterator #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl const int N = 1005; int leftside[N][N]; int rightside[N][N]; int up[N][N]; int down[N][N]; char arr[N][N]; int n, m; void fillleft() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (arr[i][j] == '.') leftside[i][j] = 1 + leftside[i][j - 1]; else leftside[i][j] = 0; } } } void fillright() { for (int i = 1; i <= n; i++) { for (int j = m; j >= 1; j--) { if (arr[i][j] == '.') rightside[i][j] = 1 + rightside[i][j + 1]; else rightside[i][j] = 0; } } } void fillup() { for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { if (arr[i][j] == '.') up[i][j] = 1 + up[i - 1][j]; else up[i][j] = 0; } } } void filldown() { for (int j = 1; j <= m; j++) { for (int i = n; i >= 1; i--) { if (arr[i][j] == '.') down[i][j] = 1 + down[i + 1][j]; else down[i][j] = 0; } } } int32_t main() { fast; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> arr[i][j]; fillleft(); fillright(); fillup(); filldown(); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (arr[i][j] == '#') continue; int l = leftside[i][j] - 1; int r = rightside[i][j] - 1; int u = up[i][j] - 1; int d = down[i][j] - 1; int val = l + r + u + d + 1; ans = max(ans, val); } } cout << ans; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define pb push_back #define pf push_front #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vip vector<pair<int, int>> #define ff first #define ss second #define int long long #define SIZE 200010 #define mod 1000000007 #define BIG 998244353 #define s(t) scanf("%d", &t) #define p(t) printf("%d\n", t) #define mii map<int, int> #define MSET(table, i) memset(table, i, sizeof(table)) #define endl '\n' #define tc \ int t; \ cin >> t; \ while (t--) #define pi 3.1415926358 #define print(x) \ for (auto el : x) \ cout << el << " "; \ cout << endl #define bits(x) __builtin_popcount(x) #define minimum(a, n) min_element(a, a + n) - a #define maximum(a, n) max_element(a, a + n) - a #define pqbig priority_queue<int> #define pqsmall priority_queue<int, vector<int>, greater<int>> #define all(v) v.begin(), v.end() #define sitr set<int>::iterator #define mitr map<int, int>::iterator #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl const int N = 2005; int leftside[N][N]; int rightside[N][N]; int up[N][N]; int down[N][N]; char arr[N][N]; int n, m; void fillleft() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (arr[i][j] == '.') leftside[i][j] = 1 + leftside[i][j - 1]; else leftside[i][j] = 0; } } } void fillright() { for (int i = 1; i <= n; i++) { for (int j = m; j >= 1; j--) { if (arr[i][j] == '.') rightside[i][j] = 1 + rightside[i][j + 1]; else rightside[i][j] = 0; } } } void fillup() { for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { if (arr[i][j] == '.') up[i][j] = 1 + up[i - 1][j]; else up[i][j] = 0; } } } void filldown() { for (int j = 1; j <= m; j++) { for (int i = n; i >= 1; i--) { if (arr[i][j] == '.') down[i][j] = 1 + down[i + 1][j]; else down[i][j] = 0; } } } int32_t main() { fast; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> arr[i][j]; fillleft(); fillright(); fillup(); filldown(); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (arr[i][j] == '#') continue; int l = leftside[i][j] - 1; int r = rightside[i][j] - 1; int u = up[i][j] - 1; int d = down[i][j] - 1; int val = l + r + u + d + 1; ans = max(ans, val); } } cout << ans; }
replace
67
68
67
68
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef long long ll; int main() { int N, M; cin >> N >> M; vector<vector<int>> H(N + 1, vector<int>(M + 1)), V(M + 1, vector<int>(N + 1)); vector<vector<pair<char, pair<int, int>>>> X( N + 1, vector<pair<char, pair<int, int>>>(M + 1)); // char, (idh, idv) int cnt = 0, res = 0, id = 0; char c; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> c; X[i][j] = make_pair(c, make_pair(0, 0)); } } // horizontal ids for (int i = 0; i < N; i++) { id = 0; cnt = 0; for (int j = 0; j < M; j++) { if (X[i][j].first == '#' or j == M - 1) { H[i][id] = cnt; // cout << i << " " << j << " " << H[i][id] << " " <<id << endl; cnt = 0; if (X[i][j].first == '#') { if (j != 0) { id++; } X[i][j].second.first = id; H[i][id] = cnt; // cout << i << " " << j << " " << H[i][id] << " " <<id << endl; id++; } else if (j == M - 1) { H[i][id]++; X[i][j].second.first = id; // cout << " hh " << H[i][id] << endl; } } else { X[i][j].second.first = id; cnt++; } } } // vertical ids for (int i = 0; i < M; i++) { id = 0; cnt = 0; for (int j = 0; j < N; j++) { if (X[j][i].first == '#' or j == N - 1) { V[i][id] = cnt; cnt = 0; // cout << i << " " << j << " " << V[i][id] << " " <<id << endl; if (X[j][i].first == '#') { if (j != 0) { id++; } X[j][i].second.second = id; V[i][id] = cnt; // cout << i << " " << j << " " << V[i][id] << " " <<id << endl; id++; } else if (j == N - 1) { V[i][id]++; X[j][i].second.second = id; // cout <<" hh" << i << " " << j << " " << V[i][id] << " " <<id << // endl; } } else { X[j][i].second.second = id; cnt++; } } } /* for(int i = 0; i < N ;i ++){ for(int j =0;j < M; j++){ cout << H[i][j] << " "; } cout << endl; } cout << endl; for(int i = 0; i < M ;i ++){ for(int j =0;j < N; j++){ cout << V[i][j] << " "; } cout << endl; }*/ // get answer int id1 = 0, id2 = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { id1 = X[i][j].second.first, id2 = X[i][j].second.second; res = max(H[i][id1] + V[j][id2] - 1, res); // cout << i << " " << j << " " << id1 << " " << id2 << " " << H[i][id1] // << " " << V[j][id2] << endl; } } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef long long ll; int main() { int N, M; cin >> N >> M; vector<vector<int>> H(N + 1, vector<int>(20000)), V(M + 1, vector<int>(20000)); vector<vector<pair<char, pair<int, int>>>> X( N + 1, vector<pair<char, pair<int, int>>>(M + 1)); // char, (idh, idv) int cnt = 0, res = 0, id = 0; char c; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> c; X[i][j] = make_pair(c, make_pair(0, 0)); } } // horizontal ids for (int i = 0; i < N; i++) { id = 0; cnt = 0; for (int j = 0; j < M; j++) { if (X[i][j].first == '#' or j == M - 1) { H[i][id] = cnt; // cout << i << " " << j << " " << H[i][id] << " " <<id << endl; cnt = 0; if (X[i][j].first == '#') { if (j != 0) { id++; } X[i][j].second.first = id; H[i][id] = cnt; // cout << i << " " << j << " " << H[i][id] << " " <<id << endl; id++; } else if (j == M - 1) { H[i][id]++; X[i][j].second.first = id; // cout << " hh " << H[i][id] << endl; } } else { X[i][j].second.first = id; cnt++; } } } // vertical ids for (int i = 0; i < M; i++) { id = 0; cnt = 0; for (int j = 0; j < N; j++) { if (X[j][i].first == '#' or j == N - 1) { V[i][id] = cnt; cnt = 0; // cout << i << " " << j << " " << V[i][id] << " " <<id << endl; if (X[j][i].first == '#') { if (j != 0) { id++; } X[j][i].second.second = id; V[i][id] = cnt; // cout << i << " " << j << " " << V[i][id] << " " <<id << endl; id++; } else if (j == N - 1) { V[i][id]++; X[j][i].second.second = id; // cout <<" hh" << i << " " << j << " " << V[i][id] << " " <<id << // endl; } } else { X[j][i].second.second = id; cnt++; } } } /* for(int i = 0; i < N ;i ++){ for(int j =0;j < M; j++){ cout << H[i][j] << " "; } cout << endl; } cout << endl; for(int i = 0; i < M ;i ++){ for(int j =0;j < N; j++){ cout << V[i][j] << " "; } cout << endl; }*/ // get answer int id1 = 0, id2 = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { id1 = X[i][j].second.first, id2 = X[i][j].second.second; res = max(H[i][id1] + V[j][id2] - 1, res); // cout << i << " " << j << " " << id1 << " " << id2 << " " << H[i][id1] // << " " << V[j][id2] << endl; } } cout << res; return 0; }
replace
8
10
8
10
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll H, W; vector<string> S; void solve() { vector<vector<ll>> L(H, vector<ll>(W)); vector<vector<ll>> R(H, vector<ll>(W)); vector<vector<ll>> U(H, vector<ll>(W)); vector<vector<ll>> D(H, vector<ll>(W)); for (int i = 0; i < H; i++) { L[i][0] = (S[i][0] == '.') ? 1 : 0; R[i][W - 1] = (S[i][W - 1] == '.') ? 1 : 0; } for (int j = 0; j < H; j++) { U[0][j] = (S[0][j] == '.') ? 1 : 0; D[H - 1][j] = (S[H - 1][j] == '.') ? 1 : 0; } for (int i = 0; i < H; i++) { for (int j = 1; j < W; j++) { if (S[i][j] == '#') { L[i][j] = 0; } else { L[i][j] = L[i][j - 1] + 1; } } } for (int i = 0; i < H; i++) { for (int j = W - 2; j >= 0; j--) { if (S[i][j] == '#') { R[i][j] = 0; } else { R[i][j] = R[i][j + 1] + 1; } } } for (int i = 1; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { U[i][j] = 0; } else { U[i][j] = U[i - 1][j] + 1; } } } for (int i = H - 2; i >= 0; i--) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { D[i][j] = 0; } else { D[i][j] = D[i + 1][j] + 1; } } } ll res = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ll tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j]; if (S[i][j] == '.') { res = max(res, tmp - 3); } else { res = max(res, tmp); } } } cout << res << '\n'; } int main() { cin >> H >> W; S.resize(H); for (int i = 0; i < H; i++) { cin >> S[i]; } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll H, W; vector<string> S; void solve() { vector<vector<ll>> L(H, vector<ll>(W)); vector<vector<ll>> R(H, vector<ll>(W)); vector<vector<ll>> U(H, vector<ll>(W)); vector<vector<ll>> D(H, vector<ll>(W)); for (int i = 0; i < H; i++) { L[i][0] = (S[i][0] == '.') ? 1 : 0; R[i][W - 1] = (S[i][W - 1] == '.') ? 1 : 0; } for (int j = 0; j < W; j++) { U[0][j] = (S[0][j] == '.') ? 1 : 0; D[H - 1][j] = (S[H - 1][j] == '.') ? 1 : 0; } for (int i = 0; i < H; i++) { for (int j = 1; j < W; j++) { if (S[i][j] == '#') { L[i][j] = 0; } else { L[i][j] = L[i][j - 1] + 1; } } } for (int i = 0; i < H; i++) { for (int j = W - 2; j >= 0; j--) { if (S[i][j] == '#') { R[i][j] = 0; } else { R[i][j] = R[i][j + 1] + 1; } } } for (int i = 1; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { U[i][j] = 0; } else { U[i][j] = U[i - 1][j] + 1; } } } for (int i = H - 2; i >= 0; i--) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { D[i][j] = 0; } else { D[i][j] = D[i + 1][j] + 1; } } } ll res = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ll tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j]; if (S[i][j] == '.') { res = max(res, tmp - 3); } else { res = max(res, tmp); } } } cout << res << '\n'; } int main() { cin >> H >> W; S.resize(H); for (int i = 0; i < H; i++) { cin >> S[i]; } solve(); return 0; }
replace
18
19
18
19
0
p03014
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using st = string; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; st abc = "abcdefghijklmnopqrstuvwxyz"; st ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; struct edge { ll to, cost; }; int main() { ll H, W; cin >> H >> W; vvc s(H, vc(W)); rep(i, H) { rep(j, W) { cin >> s[i][j]; } } vvl a(H, vl(W)), b(W, vl(H)); rep(i, H) { rep(j, W) { ll cnt = 0; if (s[i][j] == '#') { a[i][j] = 0; } else { if (j == 0 || (j != 0 && s[i][j - 1] == '#')) { cnt = 0; ll nj = j; while (nj < W && s[i][nj] == '.') { cnt++; nj++; } a[i][j] = cnt; } else { a[i][j] = a[i][j - 1]; } } } } rep(j, W) { rep(i, H) { ll cnt = 0; if (s[i][j] == '#') { b[i][j] = 0; } else { if (i == 0 || (i != 0 && s[i - 1][j] == '#')) { cnt = 0; ll ni = i; while (ni < H && s[ni][j] == '.') { cnt++; ni++; } b[i][j] = cnt; } else { b[i][j] = b[i - 1][j]; } } } } ll ans = 0; rep(i, H) { rep(j, W) { if (s[i][j] == '.') { ans = max(ans, a[i][j] + b[i][j] - 1); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using st = string; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; st abc = "abcdefghijklmnopqrstuvwxyz"; st ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; struct edge { ll to, cost; }; int main() { ll H, W; cin >> H >> W; vvc s(H, vc(W)); rep(i, H) { rep(j, W) { cin >> s[i][j]; } } vvl a(H, vl(W)), b(H, vl(W)); rep(i, H) { rep(j, W) { ll cnt = 0; if (s[i][j] == '#') { a[i][j] = 0; } else { if (j == 0 || (j != 0 && s[i][j - 1] == '#')) { cnt = 0; ll nj = j; while (nj < W && s[i][nj] == '.') { cnt++; nj++; } a[i][j] = cnt; } else { a[i][j] = a[i][j - 1]; } } } } rep(j, W) { rep(i, H) { ll cnt = 0; if (s[i][j] == '#') { b[i][j] = 0; } else { if (i == 0 || (i != 0 && s[i - 1][j] == '#')) { cnt = 0; ll ni = i; while (ni < H && s[ni][j] == '.') { cnt++; ni++; } b[i][j] = cnt; } else { b[i][j] = b[i - 1][j]; } } } } ll ans = 0; rep(i, H) { rep(j, W) { if (s[i][j] == '.') { ans = max(ans, a[i][j] + b[i][j] - 1); } } } cout << ans << endl; }
replace
33
34
33
34
-6
free(): invalid pointer
p03014
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; const int MOD = 1e9 + 7; void solve(void) { int h, w; cin >> h >> w; vector<string> g(h); for (int i = 0; i < h; i++) { cin >> g[i]; } vector<vector<int>> hs(w, vector<int>(h)), ws(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j == 0) { ws[i][j] = g[i][j] == '.'; } else { if (g[i][j] == '.') { ws[i][j] = ws[i][j - 1] + 1; } } } for (int j = w - 1; j > 0; j--) { if (ws[i][j - 1] == 0 || ws[i][j] == 0) { continue; } ws[i][j - 1] = ws[i][j]; } } for (int j = 0; j < w; j++) { for (int i = 0; i < h; i++) { if (i == 0) { hs[i][j] = g[i][j] == '.'; } else { if (g[i][j] == '.') { hs[i][j] = hs[i - 1][j] + 1; } } } for (int i = h - 1; i > 0; i--) { if (hs[i - 1][j] == 0 || hs[i][j] == 0) { continue; } hs[i - 1][j] = hs[i][j]; } } int ans = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { if (g[i][j] == '.') { ans = max(ans, hs[i][j] + ws[i][j] - 1); } } cout << ans << endl; } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; const int MOD = 1e9 + 7; void solve(void) { int h, w; cin >> h >> w; vector<string> g(h); for (int i = 0; i < h; i++) { cin >> g[i]; } vector<vector<int>> hs(2020, vector<int>(2020)), ws(2020, vector<int>(2020)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j == 0) { ws[i][j] = g[i][j] == '.'; } else { if (g[i][j] == '.') { ws[i][j] = ws[i][j - 1] + 1; } } } for (int j = w - 1; j > 0; j--) { if (ws[i][j - 1] == 0 || ws[i][j] == 0) { continue; } ws[i][j - 1] = ws[i][j]; } } for (int j = 0; j < w; j++) { for (int i = 0; i < h; i++) { if (i == 0) { hs[i][j] = g[i][j] == '.'; } else { if (g[i][j] == '.') { hs[i][j] = hs[i - 1][j] + 1; } } } for (int i = h - 1; i > 0; i--) { if (hs[i - 1][j] == 0 || hs[i][j] == 0) { continue; } hs[i - 1][j] = hs[i][j]; } } int ans = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { if (g[i][j] == '.') { ans = max(ans, hs[i][j] + ws[i][j] - 1); } } cout << ans << endl; } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
replace
13
14
13
14
0
p03014
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; bool field[h + 1][w + 1]; for (int i = 1; i <= h; i++) { char c; for (int j = 1; j <= w; j++) { cin >> c; if (c == '#') { field[i][j] = false; } else { field[i][j] = true; } } } int ans = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { int tmp = 0; if (field[i][j]) { // up for (int k = i + 1; k <= h; k++) { if (!field[k][j]) { break; } else { tmp++; } } // down for (int k = i - 1; k >= 1; k--) { if (!field[k][j]) { break; } else { tmp++; } } // right for (int k = j + 1; k <= w; k++) { if (!field[i][k]) { break; } else { tmp++; } } // down for (int k = j - 1; k >= 1; k--) { if (!field[i][k]) { break; } else { tmp++; } } ans = max(ans, tmp + 1); } } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; bool field[h + 1][w + 1]; for (int i = 1; i <= h; i++) { char c; for (int j = 1; j <= w; j++) { cin >> c; if (c == '#') { field[i][j] = false; } else { field[i][j] = true; } } } int ans = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { int tmp = 0; if (field[i][j]) { // up for (int k = i + 1; k <= h; k++) { if (!field[k][j]) { break; } else { tmp++; } } // down for (int k = i - 1; k >= 1; k--) { if (!field[k][j]) { break; } else { tmp++; } } // right for (int k = j + 1; k <= w; k++) { if (!field[i][k]) { break; } else { tmp++; } } // down for (int k = j - 1; k >= 1; k--) { if (!field[i][k]) { break; } else { tmp++; } } ans = max(ans, tmp + 1); } if (ans == h + w - 1) { break; } } } cout << ans << endl; return 0; }
insert
58
58
58
61
TLE
p03014
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; bool m[2010][2010]; int *l1[2010][2010]; int *l2[2010][2010]; int ll1[2000000]; int ll2[2000000]; int main() { int h, w; cin >> h >> w; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { m[i][j] = (s[j] == '#'); } } int ll1p = 0; int ll2p = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (m[i][j]) { l1[i][j] = NULL; ll1p++; } else { l1[i][j] = &ll1[ll1p]; ll1[ll1p]++; } } ll1p++; } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (m[j][i]) { l2[j][i] = NULL; ll2p++; } else { l2[j][i] = &ll2[ll2p]; ll2[ll2p]++; } } ll2p++; } // for(int i = 0; i < h; i++){ // for(int j = 0; j < w; j++){ // if(l2[i][j] == NULL){ // cerr << 0; // }else{ // cerr << *l2[i][j]; // } // } // cerr << endl; // } int ma = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (l1[i][j] == NULL || l2[i][j] == NULL) { continue; } int c = *l1[i][j] + *l2[i][j] - 1; ma = max(ma, c); } } cout << ma << endl; return 0; }
#include <algorithm> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; bool m[2010][2010]; int *l1[2010][2010]; int *l2[2010][2010]; int ll1[4000000]; int ll2[4000000]; int main() { int h, w; cin >> h >> w; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { m[i][j] = (s[j] == '#'); } } int ll1p = 0; int ll2p = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (m[i][j]) { l1[i][j] = NULL; ll1p++; } else { l1[i][j] = &ll1[ll1p]; ll1[ll1p]++; } } ll1p++; } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (m[j][i]) { l2[j][i] = NULL; ll2p++; } else { l2[j][i] = &ll2[ll2p]; ll2[ll2p]++; } } ll2p++; } // for(int i = 0; i < h; i++){ // for(int j = 0; j < w; j++){ // if(l2[i][j] == NULL){ // cerr << 0; // }else{ // cerr << *l2[i][j]; // } // } // cerr << endl; // } int ma = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (l1[i][j] == NULL || l2[i][j] == NULL) { continue; } int c = *l1[i][j] + *l2[i][j] - 1; ma = max(ma, c); } } cout << ma << endl; return 0; }
replace
15
17
15
17
0
p03016
C++
Runtime Error
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); i++) #define rep1(i, n) for (int i = 1; i <= int(n); i++) #define repR(i, n) for (int i = int(n) - 1; i >= 0; i--) #define rep1R(i, n) for (int i = int(n); i >= 1; i--) #define loop(i, a, B) for (int i = a; i B; i++) #define loopR(i, a, B) for (int i = a; i B; i--) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define eb emplace_back #define mp make_pair #define fst first #define snd second #ifdef LOCAL #define dump(...) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", \ dump_impl(#__VA_ARGS__, __VA_ARGS__) #define say(x) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << x << endl; #define debug if (1) void dump_impl(const char *) { cerr << endl; } template <class T, class... U> void dump_impl(const char *s, T const &x, U const &...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o, o + 3, *s)) i++; if (count(e, e + 3, *s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; dump_impl(s, y...); } #else #define dump(...) #define say(x) #define debug if (0) #endif using ll = long long; using ld = long double; #define int ll #define double ld template <class T> using pque_max = priority_queue<T>; template <class T> using pque_min = priority_queue<T, vector<T>, greater<T>>; template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> ostream &operator<<(ostream &os, T const &v) { os << "{"; for (auto const &x : v) os << " " << x; return os << " }"; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <class T, class S> ostream &operator<<(ostream &os, pair<T, S> const &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) { return is >> p.first >> p.second; } template <size_t i, class T> typename enable_if<i >= tuple_size<T>::value>::type output_tuple(ostream &, T const &) {} template <size_t i = 0, class T> typename enable_if < i<tuple_size<T>::value>::type output_tuple(ostream &os, T const &t) { os << (i ? " " : "") << get<i>(t); output_tuple<i + 1, T>(os, t); } template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) { return output_tuple(os, t), os; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; template <class T, size_t d> struct vec_impl { using type = vector<typename vec_impl<T, d - 1>::type>; template <class... U> static type make_v(size_t n, U &&...x) { return type(n, vec_impl<T, d - 1>::make_v(forward<U>(x)...)); } }; template <class T> struct vec_impl<T, 0> { using type = T; static type make_v(T const &x = {}) { return x; } }; template <class T, size_t d = 1> using vec = typename vec_impl<T, d>::type; template <class T, size_t d = 1, class... Args> auto make_v(Args &&...args) { return vec_impl<T, d>::make_v(forward<Args>(args)...); } template <class T> void quit(T const &x) { cout << x << endl; exit(0); } template <class T> constexpr bool chmin(T &x, T const &y) { if (x > y) { x = y; return true; } return false; } template <class T> constexpr bool chmax(T &x, T const &y) { if (x < y) { x = y; return true; } return false; } template <class It> constexpr auto sumof(It b, It e) { return accumulate(b, e, typename iterator_traits<It>::value_type{}); } template <class T> int sz(T const &x) { return x.size(); } const ll INF = (1LL << 62) - 1; // ~ 4.6e18 // <<< // >>> runtime modint using ll = long long; class runtime_modint { using M = runtime_modint; ll x; public: static ll &mod() { static int mod = 0; return mod; } runtime_modint(ll x = 0) { assert(mod() > 0); this->x = ((x %= mod()) < 0 ? x + mod() : x); } ll val() const { return x; } bool operator==(M r) const { return x == r.x; } bool operator!=(M r) const { return x != r.x; } M operator+() const { return *this; } M operator-() const { return {mod() - x}; } M &operator+=(M r) { if ((x += r.x) >= mod()) x -= mod(); return *this; } M &operator-=(M r) { if ((x += mod() - r.x) >= mod()) x -= mod(); return *this; } M &operator*=(M r) { (x *= r.x) %= mod(); return *this; } M operator+(M r) const { return M(*this) += r; } M operator-(M r) const { return M(*this) -= r; } M operator*(M r) const { return M(*this) *= r; } M &operator/=(M r) { return *this *= r.inv(); } M operator/(M r) const { return *this * r.inv(); } M pow(ll n) const { if (n < 0) return inv().pow(-n); M v = *this, r = 1; for (; n > 0; n >>= 1, v *= v) if (n & 1) r *= v; return r; } M inv() const { assert(x != 0); ll t = 1, v = x, q, r; while (v != 1) { q = mod() / v; r = mod() % v; if (r * 2 < v) { t *= -q; t %= mod(); v = r; } else { t *= q + 1; t %= mod(); v -= r; } } return t; } static int gen() { // assume mod():prime if (mod() == 2) return 1; vector<int> ps; int n = mod() - 1; for (int i = 2; i * i <= n; ++i) { if (n % i) continue; ps.push_back(i); do n /= i; while (n % i == 0); } if (n > 1) ps.push_back(n); n = mod() - 1; auto check = [&](M g) { for (int p : ps) if (g.pow(n / p) == 1) return false; return true; }; for (int g = 2; g <= n; ++g) if (check(g)) return g; return -1; } }; ostream &operator<<(ostream &os, runtime_modint r) { return os << r.val(); } istream &operator>>(istream &is, runtime_modint &r) { ll x; is >> x; r = x; return is; } using mint = runtime_modint; // <<< // >>> matrix template <class T> struct Matrix { int n, m; vector<vector<T>> a; Matrix() {} Matrix(int n, int m) : n(n), m(m), a(n) { assert(n > 0 && m > 0); rep(i, n) a[i].resize(m); } vector<T> const &operator[](int i) const { assert(0 <= i && i < n); return a[i]; } vector<T> &operator[](int i) { assert(0 <= i && i < n); return a[i]; } Matrix &operator+=(Matrix const &x) { assert(n == x.n && m == x.m); rep(i, n) rep(j, m) a[i][j] += x[i][j]; return *this; } Matrix &operator-=(Matrix const &x) { assert(n == x.n && m == x.m); rep(i, n) rep(j, m) a[i][j] -= x[i][j]; return *this; } Matrix operator+(Matrix const &x) const { return Matrix(*this) += x; } Matrix operator-(Matrix const &x) const { return Matrix(*this) -= x; } Matrix operator*(Matrix const &x) const { assert(m == x.n); Matrix ret(n, x.m); rep(i, n) rep(j, m) rep(k, x.m) ret[i][k] += a[i][j] * x[j][k]; return ret; } Matrix &operator*=(Matrix const &x) { auto res = (*this) * x; swap(a, res.a); return *this; } Matrix operator+() const { return *this; } Matrix operator-() const { Matrix x = *this; rep(i, n) rep(j, m) x[i][j] = -x[i][j]; return x; } Matrix &operator*=(T const &c) { rep(i, n) rep(j, m) a[i][j] *= c; return *this; } Matrix operator*(T const &c) const { return Matrix(*this) *= c; } friend Matrix operator*(T const &c, Matrix const &x) { Matrix ret = x; rep(i, x.n) rep(j, x.m) ret[i][j] = c * x[i][j]; return ret; } // Matrix& operator/=(Matrix const& x, T const& c) { // rep (i,n) rep (j,m) a[i][j] /= c; // return *this; // } // Matrix operator/(T const& c) const { // return Matrix(*this) /= c; // } static Matrix identity(int n) { Matrix ret(n, n); rep(i, n) ret[i][i] = 1; return ret; } Matrix pow(ll k) const { assert(n == m); assert(k >= 0); Matrix v = *this, r = Matrix::identity(n); for (; k > 0; k >>= 1, v *= v) if (k & 1) r *= v; return r; } }; template <class T> ostream &operator<<(ostream &os, Matrix<T> const &x) { rep(i, x.n) { os << "\n"; rep(j, x.m) os << x[i][j] << " "; } return os << "\n"; } // <<< mint f(mint x, int n) { if (n == 0) return 0; Matrix<mint> m(2, 2); mint init[2][2] = {{x, 1}, {0, 1}}; rep(i, 2) rep(j, 2) m[i][j] = init[i][j]; m = m.pow(n); return m[0][1]; } mint g(mint x, int n) { if (n == 0) return 0; Matrix<mint> m(3, 3); mint init[3][3] = {{x, 1, 0}, {0, 1, -1}, {0, 0, 1}}; rep(i, 3) rep(j, 3) m[i][j] = init[i][j]; m = m.pow(n - 1); return m[0][0] * (n - 1) + m[0][1] * (n - 2) + m[0][2]; } int32_t main() { int n, a, b, m; cin >> n >> a >> b >> m; mint::mod() = m; const int N = 18; vector<int> l(N + 1), r(N + 1); l[1] = 0; r[N] = n; rep1(i, N - 1) { int lw = -1, up = n; while (lw + 1 < up) { int mid = (lw + up) / 2; (sz(to_string(a + b * mid)) >= i + 1 ? up : lw) = mid; } r[i] = l[i + 1] = up; } // rep1 (i,N) dump(i,l[i],r[i]); vector<mint> v(N + 1); rep1(d, N) { v[d] = f(mint(10).pow(d), r[d] - l[d]) * (a + b * (r[d] - 1)) + g(mint(10).pow(d), r[d] - l[d]) * (-b); } vector<mint> s(N + 2); s[N + 1] = 1; rep1R(i, N) s[i] = s[i + 1] * mint(10).pow(i * (r[i] - l[i])); mint sum = 0; rep1(i, N) sum += v[i] * s[i + 1]; cout << sum << endl; // dump(l); dump(r); dump(v); dump(s); // dump(f(100,6)); // dump(g(100,6)); }
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); i++) #define rep1(i, n) for (int i = 1; i <= int(n); i++) #define repR(i, n) for (int i = int(n) - 1; i >= 0; i--) #define rep1R(i, n) for (int i = int(n); i >= 1; i--) #define loop(i, a, B) for (int i = a; i B; i++) #define loopR(i, a, B) for (int i = a; i B; i--) #define all(x) (x).begin(), (x).end() #define allR(x) (x).rbegin(), (x).rend() #define eb emplace_back #define mp make_pair #define fst first #define snd second #ifdef LOCAL #define dump(...) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", \ dump_impl(#__VA_ARGS__, __VA_ARGS__) #define say(x) \ cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << x << endl; #define debug if (1) void dump_impl(const char *) { cerr << endl; } template <class T, class... U> void dump_impl(const char *s, T const &x, U const &...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o, o + 3, *s)) i++; if (count(e, e + 3, *s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; dump_impl(s, y...); } #else #define dump(...) #define say(x) #define debug if (0) #endif using ll = long long; using ld = long double; #define int ll #define double ld template <class T> using pque_max = priority_queue<T>; template <class T> using pque_min = priority_queue<T, vector<T>, greater<T>>; template <class T, class = typename T::iterator, class = typename enable_if<!is_same<T, string>::value>::type> ostream &operator<<(ostream &os, T const &v) { os << "{"; for (auto const &x : v) os << " " << x; return os << " }"; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <class T, class S> ostream &operator<<(ostream &os, pair<T, S> const &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) { return is >> p.first >> p.second; } template <size_t i, class T> typename enable_if<i >= tuple_size<T>::value>::type output_tuple(ostream &, T const &) {} template <size_t i = 0, class T> typename enable_if < i<tuple_size<T>::value>::type output_tuple(ostream &os, T const &t) { os << (i ? " " : "") << get<i>(t); output_tuple<i + 1, T>(os, t); } template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) { return output_tuple(os, t), os; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; template <class T, size_t d> struct vec_impl { using type = vector<typename vec_impl<T, d - 1>::type>; template <class... U> static type make_v(size_t n, U &&...x) { return type(n, vec_impl<T, d - 1>::make_v(forward<U>(x)...)); } }; template <class T> struct vec_impl<T, 0> { using type = T; static type make_v(T const &x = {}) { return x; } }; template <class T, size_t d = 1> using vec = typename vec_impl<T, d>::type; template <class T, size_t d = 1, class... Args> auto make_v(Args &&...args) { return vec_impl<T, d>::make_v(forward<Args>(args)...); } template <class T> void quit(T const &x) { cout << x << endl; exit(0); } template <class T> constexpr bool chmin(T &x, T const &y) { if (x > y) { x = y; return true; } return false; } template <class T> constexpr bool chmax(T &x, T const &y) { if (x < y) { x = y; return true; } return false; } template <class It> constexpr auto sumof(It b, It e) { return accumulate(b, e, typename iterator_traits<It>::value_type{}); } template <class T> int sz(T const &x) { return x.size(); } const ll INF = (1LL << 62) - 1; // ~ 4.6e18 // <<< // >>> runtime modint using ll = long long; class runtime_modint { using M = runtime_modint; ll x; public: static ll &mod() { static int mod = 0; return mod; } runtime_modint(ll x = 0) { assert(mod() > 0); this->x = ((x %= mod()) < 0 ? x + mod() : x); } ll val() const { return x; } bool operator==(M r) const { return x == r.x; } bool operator!=(M r) const { return x != r.x; } M operator+() const { return *this; } M operator-() const { return {mod() - x}; } M &operator+=(M r) { if ((x += r.x) >= mod()) x -= mod(); return *this; } M &operator-=(M r) { if ((x += mod() - r.x) >= mod()) x -= mod(); return *this; } M &operator*=(M r) { (x *= r.x) %= mod(); return *this; } M operator+(M r) const { return M(*this) += r; } M operator-(M r) const { return M(*this) -= r; } M operator*(M r) const { return M(*this) *= r; } M &operator/=(M r) { return *this *= r.inv(); } M operator/(M r) const { return *this * r.inv(); } M pow(ll n) const { if (n < 0) return inv().pow(-n); M v = *this, r = 1; for (; n > 0; n >>= 1, v *= v) if (n & 1) r *= v; return r; } M inv() const { assert(x != 0); ll t = 1, v = x, q, r; while (v != 1) { q = mod() / v; r = mod() % v; if (r * 2 < v) { t *= -q; t %= mod(); v = r; } else { t *= q + 1; t %= mod(); v -= r; } } return t; } static int gen() { // assume mod():prime if (mod() == 2) return 1; vector<int> ps; int n = mod() - 1; for (int i = 2; i * i <= n; ++i) { if (n % i) continue; ps.push_back(i); do n /= i; while (n % i == 0); } if (n > 1) ps.push_back(n); n = mod() - 1; auto check = [&](M g) { for (int p : ps) if (g.pow(n / p) == 1) return false; return true; }; for (int g = 2; g <= n; ++g) if (check(g)) return g; return -1; } }; ostream &operator<<(ostream &os, runtime_modint r) { return os << r.val(); } istream &operator>>(istream &is, runtime_modint &r) { ll x; is >> x; r = x; return is; } using mint = runtime_modint; // <<< // >>> matrix template <class T> struct Matrix { int n, m; vector<vector<T>> a; Matrix() {} Matrix(int n, int m) : n(n), m(m), a(n) { assert(n > 0 && m > 0); rep(i, n) a[i].resize(m); } vector<T> const &operator[](int i) const { assert(0 <= i && i < n); return a[i]; } vector<T> &operator[](int i) { assert(0 <= i && i < n); return a[i]; } Matrix &operator+=(Matrix const &x) { assert(n == x.n && m == x.m); rep(i, n) rep(j, m) a[i][j] += x[i][j]; return *this; } Matrix &operator-=(Matrix const &x) { assert(n == x.n && m == x.m); rep(i, n) rep(j, m) a[i][j] -= x[i][j]; return *this; } Matrix operator+(Matrix const &x) const { return Matrix(*this) += x; } Matrix operator-(Matrix const &x) const { return Matrix(*this) -= x; } Matrix operator*(Matrix const &x) const { assert(m == x.n); Matrix ret(n, x.m); rep(i, n) rep(j, m) rep(k, x.m) ret[i][k] += a[i][j] * x[j][k]; return ret; } Matrix &operator*=(Matrix const &x) { auto res = (*this) * x; swap(a, res.a); return *this; } Matrix operator+() const { return *this; } Matrix operator-() const { Matrix x = *this; rep(i, n) rep(j, m) x[i][j] = -x[i][j]; return x; } Matrix &operator*=(T const &c) { rep(i, n) rep(j, m) a[i][j] *= c; return *this; } Matrix operator*(T const &c) const { return Matrix(*this) *= c; } friend Matrix operator*(T const &c, Matrix const &x) { Matrix ret = x; rep(i, x.n) rep(j, x.m) ret[i][j] = c * x[i][j]; return ret; } // Matrix& operator/=(Matrix const& x, T const& c) { // rep (i,n) rep (j,m) a[i][j] /= c; // return *this; // } // Matrix operator/(T const& c) const { // return Matrix(*this) /= c; // } static Matrix identity(int n) { Matrix ret(n, n); rep(i, n) ret[i][i] = 1; return ret; } Matrix pow(ll k) const { assert(n == m); assert(k >= 0); Matrix v = *this, r = Matrix::identity(n); for (; k > 0; k >>= 1, v *= v) if (k & 1) r *= v; return r; } }; template <class T> ostream &operator<<(ostream &os, Matrix<T> const &x) { rep(i, x.n) { os << "\n"; rep(j, x.m) os << x[i][j] << " "; } return os << "\n"; } // <<< mint f(mint x, int n) { if (n == 0) return 0; Matrix<mint> m(2, 2); mint init[2][2] = {{x, 1}, {0, 1}}; rep(i, 2) rep(j, 2) m[i][j] = init[i][j]; m = m.pow(n); return m[0][1]; } mint g(mint x, int n) { if (n == 0) return 0; Matrix<mint> m(3, 3); mint init[3][3] = {{x, 1, 0}, {0, 1, -1}, {0, 0, 1}}; rep(i, 3) rep(j, 3) m[i][j] = init[i][j]; m = m.pow(n - 1); return m[0][0] * (n - 1) + m[0][1] * (n - 2) + m[0][2]; } int32_t main() { int n, a, b, m; cin >> n >> a >> b >> m; mint::mod() = m; const int N = 18; vector<int> l(N + 1), r(N + 1); l[1] = 0; r[N] = n; rep1(i, N - 1) { int lw = -1, up = n; while (lw + 1 < up) { int mid = (lw + up) / 2; (sz(to_string(a + b * mid)) >= i + 1 ? up : lw) = mid; } r[i] = l[i + 1] = up; } // rep1 (i,N) dump(i,l[i],r[i]); vector<mint> v(N + 1); rep1(d, N) { v[d] = f(mint(10).pow(d), r[d] - l[d]) * (a + b * (r[d] - 1)) + g(mint(10).pow(d), r[d] - l[d]) * (-b); } vector<mint> s(N + 2); s[N + 1] = 1; rep1R(i, N) s[i] = s[i + 1] * mint(10).pow(i).pow(r[i] - l[i]); mint sum = 0; rep1(i, N) sum += v[i] * s[i + 1]; cout << sum << endl; // dump(l); dump(r); dump(v); dump(s); // dump(f(100,6)); // dump(g(100,6)); }
replace
364
365
364
365
0
p03016
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "../include/debug.hpp" #else #define debug(...) 42 #define rdfile(...) 42 #endif typedef vector<long long> vec; typedef vector<vector<long long>> mat; const long long INF = LLONG_MAX; long long L, A, B, M; long long pow10(long long n, long long M) { if (n == 0) return 1; if (n % 2 == 0) { long long t = pow10(n / 2, M); return (t * t) % M; } return (10 * pow10(n - 1, M)) % M; } mat mult(mat A, mat B) { mat ret(A.size(), vec(B[0].size(), 0)); for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < B[0].size(); ++j) { for (int k = 0; k < A[0].size(); ++k) { ret[i][j] += A[i][k] * B[k][j]; ret[i][j] %= M; } } } return ret; } mat pow(mat A, long long n) { if (n == 0) { return {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; } if (n % 2 == 0) { mat t = pow(A, n / 2); return mult(t, t); } return mult(A, pow(A, n - 1)); } int main() { ios::sync_with_stdio(false); cin.tie(0); // rdfile("_input.txt"); cin >> L >> A >> B >> M; long long ans = 0; for (long long d = 1; d <= 18; ++d) { // d:=桁数 long long l = pow10(d - 1, INF) - A; l = (l % B && l > 0) ? l / B + 1 : l / B; l = max(l, 0LL); long long r = pow10(d, INF) - A; r = (r % B && r > 0) ? r / B + 1 : r / B; r = min(r, L); if (l >= r) continue; ans = (ans * pow10((r - l) * d, M)) % M; long long si, ai; si = ((A % M) + (B % M) * (l % M)) % M; ai = si; mat m = {{pow10(d, M), 0, 0}, {1, 1, 0}, {B % M, B % M, 1}}; m = pow(m, r - l - 1); ans += (ai * m[0][0]) % M + (si * m[1][0]) % M + m[2][0]; ans %= M; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "../include/debug.hpp" #else #define debug(...) 42 #define rdfile(...) 42 #endif typedef vector<long long> vec; typedef vector<vector<long long>> mat; const long long INF = LLONG_MAX; long long L, A, B, M; long long pow10(long long n, long long M) { if (n == 0) return 1; if (n % 2 == 0) { long long t = pow10(n / 2, M); return (t * t) % M; } return (10 * pow10(n - 1, M)) % M; } mat mult(mat A, mat B) { mat ret(A.size(), vec(B[0].size(), 0)); for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < B[0].size(); ++j) { for (int k = 0; k < A[0].size(); ++k) { ret[i][j] += A[i][k] * B[k][j]; ret[i][j] %= M; } } } return ret; } mat pow(mat A, long long n) { if (n == 0) { return {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; } if (n % 2 == 0) { mat t = pow(A, n / 2); return mult(t, t); } return mult(A, pow(A, n - 1)); } int main() { ios::sync_with_stdio(false); cin.tie(0); // rdfile("_input.txt"); cin >> L >> A >> B >> M; long long ans = 0; for (long long d = 1; d <= 18; ++d) { // d:=桁数 long long l = pow10(d - 1, INF) - A; l = (l % B && l > 0) ? l / B + 1 : l / B; l = max(l, 0LL); long long r = pow10(d, INF) - A; r = (r % B && r > 0) ? r / B + 1 : r / B; r = min(r, L); if (l >= r) continue; // ans = (ans * pow10((r-l)*d, M)) % M; for (int i = 0; i < d; ++i) { ans *= pow10(r - l, M); ans %= M; } long long si, ai; si = ((A % M) + (B % M) * (l % M)) % M; ai = si; mat m = {{pow10(d, M), 0, 0}, {1, 1, 0}, {B % M, B % M, 1}}; m = pow(m, r - l - 1); ans += (ai * m[0][0]) % M + (si * m[1][0]) % M + m[2][0]; ans %= M; } cout << ans << endl; return 0; }
replace
70
71
70
76
0
p03016
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define LL long long #define PB push_back #define MP make_pair LL L, A, B, M; // 行列 // http://www.yamamo10.jp/yamamoto/comp/cpp/ex_class/matrix.php class Matrix { int row; // 行 int column; // 列 long long **p_top; // 配列の最初 public: Matrix(int i = 1, int j = 1) { if (i < 1 || j < 1) exit(1); row = i; column = j; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値の初期化 for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = 0; } Matrix(const Matrix &cp) { row = cp.row; column = cp.column; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値のコピー for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = cp.p_top[k1][k2]; } ~Matrix() { delete[] * p_top; delete[] p_top; } int row_size() { return (row); } int column_size() { return (column); } void change_size(int i, int j) { delete[] * p_top; delete[] p_top; if (i < 1 || j < 1) exit(1); row = i; column = j; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値の初期化 for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = 0; } // 演算子 long long *&operator[](int i) { return (p_top[i]); } Matrix operator=(const Matrix &a) { if (row != a.row || column != a.column) { change_size(a.row, a.column); } for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { p_top[i][j] = a.p_top[i][j]; } } return (*this); } Matrix operator+(const Matrix &a) { if (row != a.row || column != a.column) exit(0); Matrix r(row, column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { r.p_top[i][j] = p_top[i][j] + a.p_top[i][j]; } } return (r); } Matrix operator-(const Matrix &a) { if (row != a.row || column != a.column) exit(0); Matrix r(row, column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { r.p_top[i][j] = p_top[i][j] - a.p_top[i][j]; } } return (r); } Matrix operator*(const Matrix &a) { if (column != a.row) exit(0); Matrix r(row, a.column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= a.column; j++) { for (int k = 1; k <= column; k++) { r.p_top[i][j] += (p_top[i][k] % M) * (a.p_top[k][j] % M); r.p_top[i][j] %= M; } } } return (r); } // 定数倍 friend Matrix operator*(const Matrix &a, long long b) { Matrix r(a.row, a.column); for (int i = 1; i <= a.row; i++) { for (int j = 1; j <= a.column; j++) { r[i][j] = b * a.p_top[i][j]; } } return (r); } friend Matrix operator*(long long b, const Matrix &a) { Matrix r(a.row, a.column); for (int i = 1; i <= a.row; i++) { for (int j = 1; j <= a.column; j++) { r[i][j] = b * a.p_top[i][j]; } } return (r); } }; // 累乗 O(log N) long long power(long long x, long long N) { if (N == 1) return x; long long tmp = power(x, N / 2); if (N % 2 == 0) return tmp * tmp; else return tmp * tmp * x; } Matrix power(Matrix m, int N) { if (N == 1) return m; Matrix tmp = power(m, N / 2); if (N % 2 == 0) return tmp * tmp; else return tmp * tmp * m; } LL binary_search(LL maximum) { LL ok = -1; LL ng = L; while (ng - ok > 1) { LL m = (ok + ng) / 2; LL tmp = A + B * m; if (tmp <= maximum) ok = m; else ng = m; } return ok; } int main() { cin >> L >> A >> B >> M; Matrix m(1, 3); m[1][1] = 0; m[1][2] = A; m[1][3] = 1; LL now = 0; for (LL i = 1; i <= 18; i++) { Matrix mask(3, 3); mask[1][1] = power(10, i); mask[2][1] = 1; mask[2][2] = 1; mask[3][2] = B; mask[3][3] = 1; LL num = binary_search(now * 10 + 9) - binary_search(now); now = now * 10 + 9; if (num > 0) m = m * power(mask, num); } cout << m[1][1] << endl; }
#include "bits/stdc++.h" using namespace std; #define LL long long #define PB push_back #define MP make_pair LL L, A, B, M; // 行列 // http://www.yamamo10.jp/yamamoto/comp/cpp/ex_class/matrix.php class Matrix { int row; // 行 int column; // 列 long long **p_top; // 配列の最初 public: Matrix(int i = 1, int j = 1) { if (i < 1 || j < 1) exit(1); row = i; column = j; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値の初期化 for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = 0; } Matrix(const Matrix &cp) { row = cp.row; column = cp.column; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値のコピー for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = cp.p_top[k1][k2]; } ~Matrix() { delete[] * p_top; delete[] p_top; } int row_size() { return (row); } int column_size() { return (column); } void change_size(int i, int j) { delete[] * p_top; delete[] p_top; if (i < 1 || j < 1) exit(1); row = i; column = j; // 配列のメモリ領域を動的に確保 p_top = new long long *[row + 1]; *p_top = new long long[row * column + 1]; for (int k = 1; k <= row; k++) *(p_top + k) = *p_top + ((k - 1) * column); // 値の初期化 for (int k1 = 1; k1 <= row; k1++) for (int k2 = 1; k2 <= column; k2++) p_top[k1][k2] = 0; } // 演算子 long long *&operator[](int i) { return (p_top[i]); } Matrix operator=(const Matrix &a) { if (row != a.row || column != a.column) { change_size(a.row, a.column); } for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { p_top[i][j] = a.p_top[i][j]; } } return (*this); } Matrix operator+(const Matrix &a) { if (row != a.row || column != a.column) exit(0); Matrix r(row, column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { r.p_top[i][j] = p_top[i][j] + a.p_top[i][j]; } } return (r); } Matrix operator-(const Matrix &a) { if (row != a.row || column != a.column) exit(0); Matrix r(row, column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { r.p_top[i][j] = p_top[i][j] - a.p_top[i][j]; } } return (r); } Matrix operator*(const Matrix &a) { if (column != a.row) exit(0); Matrix r(row, a.column); for (int i = 1; i <= row; i++) { for (int j = 1; j <= a.column; j++) { for (int k = 1; k <= column; k++) { r.p_top[i][j] += (p_top[i][k] % M) * (a.p_top[k][j] % M); r.p_top[i][j] %= M; } } } return (r); } // 定数倍 friend Matrix operator*(const Matrix &a, long long b) { Matrix r(a.row, a.column); for (int i = 1; i <= a.row; i++) { for (int j = 1; j <= a.column; j++) { r[i][j] = b * a.p_top[i][j]; } } return (r); } friend Matrix operator*(long long b, const Matrix &a) { Matrix r(a.row, a.column); for (int i = 1; i <= a.row; i++) { for (int j = 1; j <= a.column; j++) { r[i][j] = b * a.p_top[i][j]; } } return (r); } }; // 累乗 O(log N) long long power(long long x, long long N) { if (N == 1) return x; long long tmp = power(x, N / 2); if (N % 2 == 0) return tmp * tmp; else return tmp * tmp * x; } Matrix power(Matrix m, long long N) { if (N == 1) return m; Matrix tmp = power(m, N / 2); if (N % 2 == 0) return tmp * tmp; else return tmp * tmp * m; } LL binary_search(LL maximum) { LL ok = -1; LL ng = L; while (ng - ok > 1) { LL m = (ok + ng) / 2; LL tmp = A + B * m; if (tmp <= maximum) ok = m; else ng = m; } return ok; } int main() { cin >> L >> A >> B >> M; Matrix m(1, 3); m[1][1] = 0; m[1][2] = A; m[1][3] = 1; LL now = 0; for (LL i = 1; i <= 18; i++) { Matrix mask(3, 3); mask[1][1] = power(10, i); mask[2][1] = 1; mask[2][2] = 1; mask[3][2] = B; mask[3][3] = 1; LL num = binary_search(now * 10 + 9) - binary_search(now); now = now * 10 + 9; if (num > 0) m = m * power(mask, num); } cout << m[1][1] << endl; }
replace
154
155
154
155
0
p03016
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const ll inf = 1LL << 60; #define all(x) (x).begin(), (x).end() #define puts(x) cout << x << endl #define rep(i, m, n) for (ll i = m; i < n; ++i) #define pb push_back #define fore(i, a) for (auto &i : a) #define rrep(i, m, n) for (ll i = m; i >= n; --i) ll L, A, B, M; vector<vector<ll>> matrix_mul(vector<vector<ll>> a, vector<vector<ll>> b) { vector<vector<ll>> res(a.size(), vector<ll>(b[0].size())); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b[0].size(); j++) { ll temp = 0; for (int k = 0; k < b.size(); k++) { a[i][k] %= M; b[k][j] %= M; temp += (a[i][k] * b[k][j]) % M; temp %= M; } res[i][j] = temp; } } return res; } vector<vector<ll>> matrix_pow(vector<vector<ll>> a, ll n) { vector<vector<ll>> E(a.size(), vector<ll>(a.size(), 0)); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { E[i][j] = (i == j); } } if (n == 0) return E; else if (n % 2 == 0) return matrix_mul(matrix_pow(a, n / 2), matrix_pow(a, n / 2)); else return matrix_mul(a, matrix_pow(a, n - 1)); } ll po(ll n) { ll ret = 1; for (int i = 0; i < n; i++) ret *= 10LL; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> L >> A >> B >> M; ll pre = -1; vector<vector<ll>> cur(3, vector<ll>(1, 0)); cur[1][0] = A; cur[2][0] = 1; for (int i = 1; i <= 18; i++) { vector<vector<ll>> M(3, vector<ll>(3, 0)); M[0] = {po(i), 1, 0}; M[1] = {0, 1, B}; M[2] = {0, 0, 1}; if (A + (L - 1) * B < po(i)) { cur = matrix_mul(matrix_pow(M, L - 1 - pre), cur); break; } ll ok = pre, ng = L - 1; while (ng - ok > 1) { ll mid = (ng + ok) / 2LL; if (A + mid * B < po(i)) ok = mid; else ng = mid; } vector<vector<ll>> temp = matrix_pow(M, ok - pre); cur = matrix_mul(temp, cur); pre = ok; } puts(cur[0][0]); return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const ll inf = 1LL << 60; #define all(x) (x).begin(), (x).end() #define puts(x) cout << x << endl #define rep(i, m, n) for (ll i = m; i < n; ++i) #define pb push_back #define fore(i, a) for (auto &i : a) #define rrep(i, m, n) for (ll i = m; i >= n; --i) ll L, A, B, M; vector<vector<ll>> matrix_mul(vector<vector<ll>> a, vector<vector<ll>> b) { vector<vector<ll>> res(a.size(), vector<ll>(b[0].size())); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b[0].size(); j++) { ll temp = 0; for (int k = 0; k < b.size(); k++) { a[i][k] %= M; b[k][j] %= M; temp += (a[i][k] * b[k][j]) % M; temp %= M; } res[i][j] = temp; } } return res; } vector<vector<ll>> matrix_pow(vector<vector<ll>> a, ll n) { vector<vector<ll>> E(a.size(), vector<ll>(a.size(), 0)); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { E[i][j] = (i == j); } } while (n > 0) { if (n & 1) E = matrix_mul(E, a); a = matrix_mul(a, a); n >>= 1; } return E; } ll po(ll n) { ll ret = 1; for (int i = 0; i < n; i++) ret *= 10LL; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> L >> A >> B >> M; ll pre = -1; vector<vector<ll>> cur(3, vector<ll>(1, 0)); cur[1][0] = A; cur[2][0] = 1; for (int i = 1; i <= 18; i++) { vector<vector<ll>> M(3, vector<ll>(3, 0)); M[0] = {po(i), 1, 0}; M[1] = {0, 1, B}; M[2] = {0, 0, 1}; if (A + (L - 1) * B < po(i)) { cur = matrix_mul(matrix_pow(M, L - 1 - pre), cur); break; } ll ok = pre, ng = L - 1; while (ng - ok > 1) { ll mid = (ng + ok) / 2LL; if (A + mid * B < po(i)) ok = mid; else ng = mid; } vector<vector<ll>> temp = matrix_pow(M, ok - pre); cur = matrix_mul(temp, cur); pre = ok; } puts(cur[0][0]); return 0; }
replace
58
64
58
65
TLE
p03016
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<ll> vec; typedef vector<vec> mat; ll L, A, B, MOD; mat mul(mat &a, mat &b) { mat c(a.size(), vec(b[0].size())); rep(i, a.size()) rep(j, b[0].size()) rep(k, b.size())(c[i][j] += a[i][k] * b[k][j]) %= MOD; return c; } mat ppow(mat &a, ll b) { mat res(a.size(), vec(a.size())); rep(i, a.size()) res[i][i] = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll ppow(ll a, ll b) { a %= MOD; ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } ll lb(ll x) { ll ok = L, ng = -1; while (ok - ng > 1) { ll t = (ok + ng) / 2; if (A + B * t >= x) ok = t; else ng = t; } return ok; } int main() { cin >> L >> A >> B >> MOD; ll d = 1; ll ans = 0; for (ll i = 1; i <= 18; i++) { ll l = lb(d), r = lb(d * 10); (ans *= ppow(10, i * (r - l))) %= MOD; ll s = (A + B % MOD * l) % MOD; mat M1{{d * 10 % MOD, 1, 0}, {0, 1, 1}, {0, 0, 1}}; mat M2{{0}, {s}, {B % MOD}}; mat res = ppow(M1, r - l); M2 = mul(res, M2); (ans += M2[0][0]) %= MOD; d *= 10; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<ll> vec; typedef vector<vec> mat; ll L, A, B, MOD; mat mul(mat &a, mat &b) { mat c(a.size(), vec(b[0].size())); rep(i, a.size()) rep(j, b[0].size()) rep(k, b.size())(c[i][j] += a[i][k] * b[k][j]) %= MOD; return c; } mat ppow(mat &a, ll b) { mat res(a.size(), vec(a.size())); rep(i, a.size()) res[i][i] = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll ppow(ll a, ll b) { a %= MOD; ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } ll lb(ll x) { ll ok = L, ng = -1; while (ok - ng > 1) { ll t = (ok + ng) / 2; if (A + B * t >= x) ok = t; else ng = t; } return ok; } int main() { cin >> L >> A >> B >> MOD; ll d = 1; ll ans = 0; for (ll i = 1; i <= 18; i++) { ll l = lb(d), r = lb(d * 10); (ans *= ppow(d * 10, (r - l))) %= MOD; ll s = (A + B % MOD * l) % MOD; mat M1{{d * 10 % MOD, 1, 0}, {0, 1, 1}, {0, 0, 1}}; mat M2{{0}, {s}, {B % MOD}}; mat res = ppow(M1, r - l); M2 = mul(res, M2); (ans += M2[0][0]) %= MOD; d *= 10; } cout << ans << endl; }
replace
59
60
59
60
TLE
p03016
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pii; typedef vector<ll> Vi; typedef vector<Vi> VVi; const double EPS = (1e-7); const ll INF = (1e13); const double PI = (acos(-1)); const ll MOD = ll(1e9) + 7; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n; i > -1; i--) #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define SZ(x) ((ll)(x).size()) #define pb push_back #define mp make_pair // chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す // chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define dump(x) cerr << #x << "= " << (x) << endl; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll pow(ll a, ll b) { if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a; } ll pow(ll a, ll b, ll m) { if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m; } ll residue(ll a, ll m) { return ((a % m) + m) % m; }; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; Vi mul(VVi a, Vi b, ll m) { ll x = a.size(), y = a[0].size(), y1 = b.size(); assert(y == y1); REP(i, x) REP(j, y) { a[i][j] = residue(a[i][j], m); } REP(i, y) b[i] = residue(b[i], m); Vi c(x, 0); REP(i, x) REP(j, y) { c[i] += a[i][j] * b[j] % m; c[i] %= m; } return c; } VVi mul(VVi a, VVi b, ll m) { // a * b 要素はmで割ったあまり ll x = a.size(), y1 = a[0].size(), y2 = b.size(), z = b[0].size(); assert(y1 == y2); ll y = y1; REP(i, x) REP(j, y) a[i][j] = residue(a[i][j], m); REP(i, y) REP(j, z) b[i][j] = residue(b[i][j], m); VVi c(x, Vi(z, 0)); REP(i, x) REP(j, z) REP(k, y) { c[i][j] += (a[i][k] * b[k][j]) % m; c[i][j] %= m; } return c; } VVi pow(VVi a, ll n, ll m) { if (n == 0) { ll x = a.size(); VVi I(x, Vi(x, 0)); REP(i, x) I[i][i] = 1; return I; } if (n % 2 == 0) return mul(pow(a, n / 2, m), pow(a, n / 2, m), m); else return mul(pow(a, n - 1, m), a, m); } int main() { ll l, a, b, m; cin >> l >> a >> b >> m; Vi p(18); REP(i, 18) { ll x = max(0ll, (pow(10ll, i) - a + b - 1) / b); chmin(x, l); ll y = max(0ll, (pow(10ll, i + 1) - a + b - 1) / b); chmin(y, l); p[i] = y - x; // printf("p[%lld] = (%lld桁の項数) = %lld\n", i, i + 1, p[i]); } Vi X = {0, residue(a - b, m), 1}; VVi Y = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; REP(i, 18) { VVi A = {{pow(10, i + 1, m), 1, b}, {0, 1, b}, {0, 0, 1}}; Y = mul(pow(A, p[i], m), Y, m); // printf("i = %lld, X[0] = %lld, X[1] = %lld, X[2] = %lld\n", i, X[0], // X[1], X[2]); } Vi Z = mul(Y, X, m); cout << Z[0] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pii; typedef vector<ll> Vi; typedef vector<Vi> VVi; const double EPS = (1e-7); const ll INF = (1e13); const double PI = (acos(-1)); const ll MOD = ll(1e9) + 7; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n; i > -1; i--) #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define SZ(x) ((ll)(x).size()) #define pb push_back #define mp make_pair // chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す // chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define dump(x) cerr << #x << "= " << (x) << endl; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll pow(ll a, ll b) { if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a; } ll pow(ll a, ll b, ll m) { if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m; } ll residue(ll a, ll m) { return ((a % m) + m) % m; }; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; Vi mul(VVi a, Vi b, ll m) { ll x = a.size(), y = a[0].size(), y1 = b.size(); assert(y == y1); REP(i, x) REP(j, y) { a[i][j] = residue(a[i][j], m); } REP(i, y) b[i] = residue(b[i], m); Vi c(x, 0); REP(i, x) REP(j, y) { c[i] += a[i][j] * b[j] % m; c[i] %= m; } return c; } VVi mul(VVi a, VVi b, ll m) { // a * b 要素はmで割ったあまり ll x = a.size(), y1 = a[0].size(), y2 = b.size(), z = b[0].size(); assert(y1 == y2); ll y = y1; REP(i, x) REP(j, y) a[i][j] = residue(a[i][j], m); REP(i, y) REP(j, z) b[i][j] = residue(b[i][j], m); VVi c(x, Vi(z, 0)); REP(i, x) REP(j, z) REP(k, y) { c[i][j] += (a[i][k] * b[k][j]) % m; c[i][j] %= m; } return c; } VVi pow(VVi a, ll n, ll m) { if (n == 0) { ll x = a.size(); VVi I(x, Vi(x, 0)); REP(i, x) I[i][i] = 1; return I; } if (n % 2 == 0) { VVi b = mul(a, a, m); return pow(b, n / 2, m); } else return mul(pow(a, n - 1, m), a, m); } int main() { ll l, a, b, m; cin >> l >> a >> b >> m; Vi p(18); REP(i, 18) { ll x = max(0ll, (pow(10ll, i) - a + b - 1) / b); chmin(x, l); ll y = max(0ll, (pow(10ll, i + 1) - a + b - 1) / b); chmin(y, l); p[i] = y - x; // printf("p[%lld] = (%lld桁の項数) = %lld\n", i, i + 1, p[i]); } Vi X = {0, residue(a - b, m), 1}; VVi Y = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; REP(i, 18) { VVi A = {{pow(10, i + 1, m), 1, b}, {0, 1, b}, {0, 0, 1}}; Y = mul(pow(A, p[i], m), Y, m); // printf("i = %lld, X[0] = %lld, X[1] = %lld, X[2] = %lld\n", i, X[0], // X[1], X[2]); } Vi Z = mul(Y, X, m); cout << Z[0] << endl; }
replace
100
103
100
104
TLE
p03016
C++
Time Limit Exceeded
// // Created by yamunaku on 2019/11/05. // #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repl(i, l, r) for (int i = (l); i < (r); i++) #define per(i, n) for (int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(), (x).end() #define MOD9 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP << " " << #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl #define CFS \ cin.tie(0); \ ios::sync_with_stdio(false) #define CST(x) cout << fixed << setprecision(x) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> mti; typedef vector<ll> vl; typedef vector<vector<ll>> mtl; ll b, m; ll modpow(ll x, ll a) { ll ans = 1; while (a > 0) { if (a % 2) ans = ans * x % m; a /= 2; x = x * x % m; } return ans; } void matprod(mtl &ret, mtl &x, mtl &y) { int n = x.size(); mtl ans = mtl(n, vl(n, 0)); rep(i, n) { rep(j, n) { rep(k, n) { ans[i][j] = (ans[i][j] + x[i][k] * y[k][j] % m) % m; } } } ret = ans; } void matpow(mtl &ret, mtl &x, ll a) { int n = x.size(); mtl ans = mtl(n, vl(n, 0)); rep(i, n) ans[i][i] = 1; while (a > 0) { if (a % 2) matprod(ans, ans, x); a /= 2; matprod(x, x, x); } ret = ans; } ll solve(ll n, ll c, ll t) { mtl x = {{1, 0, 0}, {b, 1, 0}, {0, 1, t}}; matpow(x, x, n); return (x[2][0] + x[2][1] * c % m) % m; } int main() { ll s, a; cin >> s >> a >> b >> m; ll ans = 0; ll now = 0; for (ll t = 10, k = 1; now < s && k <= 18; t *= 10, k++) { if (b * now + a < t) { ll w = max(0ll, min((t - 1 - (b * now + a)) / b + 1, s - now)); ans = ans * modpow(10, w * k) % m; ans = (ans + solve(w, (b * now + a) % m, t % m)) % m; now += w; } } cout << ans << endl; return 0; }
// // Created by yamunaku on 2019/11/05. // #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repl(i, l, r) for (int i = (l); i < (r); i++) #define per(i, n) for (int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(), (x).end() #define MOD9 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP << " " << #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl #define CFS \ cin.tie(0); \ ios::sync_with_stdio(false) #define CST(x) cout << fixed << setprecision(x) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> mti; typedef vector<ll> vl; typedef vector<vector<ll>> mtl; ll b, m; ll modpow(ll x, ll a) { ll ans = 1; while (a > 0) { if (a % 2) ans = ans * x % m; a /= 2; x = x * x % m; } return ans; } void matprod(mtl &ret, mtl &x, mtl &y) { int n = x.size(); mtl ans = mtl(n, vl(n, 0)); rep(i, n) { rep(j, n) { rep(k, n) { ans[i][j] = (ans[i][j] + x[i][k] * y[k][j] % m) % m; } } } ret = ans; } void matpow(mtl &ret, mtl &x, ll a) { int n = x.size(); mtl ans = mtl(n, vl(n, 0)); rep(i, n) ans[i][i] = 1; while (a > 0) { if (a % 2) matprod(ans, ans, x); a /= 2; matprod(x, x, x); } ret = ans; } ll solve(ll n, ll c, ll t) { mtl x = {{1, 0, 0}, {b, 1, 0}, {0, 1, t}}; matpow(x, x, n); return (x[2][0] + x[2][1] * c % m) % m; } int main() { ll s, a; cin >> s >> a >> b >> m; ll ans = 0; ll now = 0; for (ll t = 10, k = 1; now < s && k <= 18; t *= 10, k++) { if (b * now + a < t) { ll w = max(0ll, min((t - 1 - (b * now + a)) / b + 1, s - now)); rep(i, k) { ans = ans * modpow(10, w) % m; } ans = (ans + solve(w, (b * now + a) % m, t % m)) % m; now += w; } } cout << ans << endl; return 0; }
replace
83
84
83
84
TLE
p03016
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i) #define ALL(v) (v).begin(), (v).end() #define CLR(t, v) memset(t, (v), sizeof(t)) template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << "," << a.second << ")"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << (*i) << " "; cout << endl; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } ll MOD; #define SZ(v) ((int)(v).size()) typedef vector<ll> Array; typedef vector<Array> Matrix; Matrix zero(int N) { return Matrix(N, Array(N)); } Matrix identity(int N) { Matrix A = zero(N); REP(i, N) A[i][i] = 1; return A; } Array mul(const Matrix &A, const Array &x) { const int N = SZ(A); const int M = SZ(A[0]); Array y(N); REP(i, N) REP(j, M) { y[i] += A[i][j] * x[j]; y[i] %= MOD; } return y; } Matrix mul(const Matrix &A, const Matrix &B) { const int N = SZ(A); const int P = SZ(A[0]); const int M = SZ(B[0]); Matrix C(N, Array(M)); REP(i, N) REP(j, M) REP(k, P) { C[i][j] += A[i][k] * B[k][j]; if (C[i][j] >= MOD) C[i][j] %= MOD; } return C; } Matrix pow(Matrix A, ll b) { Matrix C = identity(SZ(A)); while (b > 0) { if ((b & 1) == 1) C = mul(C, A); A = mul(A, A); b >>= 1; } return C; } void print(const Matrix &A) { REP(i, SZ(A)) { REP(j, SZ(A[0])) { cout << A[i][j] << " "; } cout << endl; } cout << "---------------------" << endl; } ll mod_pow(ll a, ll b, ll p) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b >>= 1; } return res; } int getKeta(ll x) { int res = 0; while (x > 0) { x /= 10; res++; } return res; } // k 桁になる要素の添え字の両端の添え字 pair<ll, ll> ketaRange(ll A, ll B, ll L, int k) { ll lb, ub; { ll lo = -1; ll hi = L; while (hi - lo > 1) { ll mid = (hi + lo) / 2; int keta = getKeta(A + B * mid); if (keta < k) { lo = mid; } else { hi = mid; } } lb = hi; } { ll lo = -1; ll hi = L; while (hi - lo > 1) { ll mid = (hi + lo) / 2; int keta = getKeta(A + B * mid); if (keta <= k) { lo = mid; } else { hi = mid; } } ub = hi; } return {lb, ub}; } ll solve(ll A, ll B, ll L) { ll res = 0; for (int k = 1; k <= 18; k++) { ll from, to; tie(from, to) = ketaRange(A, B, L, k); ll n = to - from; if (n == 0) continue; // cout << k << ":" << from << " " << to << endl; const ll TEN = pow(10, k); Matrix M = zero(3); M[0][0] = TEN; M[0][1] = 1; M[1][1] = 1; M[1][2] = 1; M[2][2] = 1; Array b = Array({0, A + from * B, B}); REP(i, 3) REP(j, 3) M[i][j] %= MOD; REP(i, b.size()) b[i] %= MOD; M = pow(M, n); Array R = mul(M, b); // cout << "k=" << k << ", n="<< n << ", res=" << R[0] << endl; if (k * n < 0) while (true) ; res = (res * mod_pow(10, k * n, MOD) % MOD + R[0] % MOD) % MOD; } return res; } int main2() { ll L, A, B; cin >> L >> A >> B >> MOD; ll ans = solve(A, B, L); cout << ans << endl; return 0; } int main() { // ll A = 1; // ll B = 170; // ll L = 30; // REP(i, L) { // ll s = A + B * i; // cout << getKeta(s) << " " << s << endl; // } // for (int k = 1; k <= 10; k++) { // cout << k << ":" << ketaRange(A, B, L, k) << endl; // } // return 0; #ifdef LOCAL for (; !cin.eof(); cin >> ws) #endif main2(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i) #define ALL(v) (v).begin(), (v).end() #define CLR(t, v) memset(t, (v), sizeof(t)) template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << "," << a.second << ")"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << (*i) << " "; cout << endl; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } ll MOD; #define SZ(v) ((int)(v).size()) typedef vector<ll> Array; typedef vector<Array> Matrix; Matrix zero(int N) { return Matrix(N, Array(N)); } Matrix identity(int N) { Matrix A = zero(N); REP(i, N) A[i][i] = 1; return A; } Array mul(const Matrix &A, const Array &x) { const int N = SZ(A); const int M = SZ(A[0]); Array y(N); REP(i, N) REP(j, M) { y[i] += A[i][j] * x[j]; y[i] %= MOD; } return y; } Matrix mul(const Matrix &A, const Matrix &B) { const int N = SZ(A); const int P = SZ(A[0]); const int M = SZ(B[0]); Matrix C(N, Array(M)); REP(i, N) REP(j, M) REP(k, P) { C[i][j] += A[i][k] * B[k][j]; if (C[i][j] >= MOD) C[i][j] %= MOD; } return C; } Matrix pow(Matrix A, ll b) { Matrix C = identity(SZ(A)); while (b > 0) { if ((b & 1) == 1) C = mul(C, A); A = mul(A, A); b >>= 1; } return C; } void print(const Matrix &A) { REP(i, SZ(A)) { REP(j, SZ(A[0])) { cout << A[i][j] << " "; } cout << endl; } cout << "---------------------" << endl; } ll mod_pow(ll a, ll b, ll p) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b >>= 1; } return res; } int getKeta(ll x) { int res = 0; while (x > 0) { x /= 10; res++; } return res; } // k 桁になる要素の添え字の両端の添え字 pair<ll, ll> ketaRange(ll A, ll B, ll L, int k) { ll lb, ub; { ll lo = -1; ll hi = L; while (hi - lo > 1) { ll mid = (hi + lo) / 2; int keta = getKeta(A + B * mid); if (keta < k) { lo = mid; } else { hi = mid; } } lb = hi; } { ll lo = -1; ll hi = L; while (hi - lo > 1) { ll mid = (hi + lo) / 2; int keta = getKeta(A + B * mid); if (keta <= k) { lo = mid; } else { hi = mid; } } ub = hi; } return {lb, ub}; } ll solve(ll A, ll B, ll L) { ll res = 0; for (int k = 1; k <= 18; k++) { ll from, to; tie(from, to) = ketaRange(A, B, L, k); ll n = to - from; if (n == 0) continue; // cout << k << ":" << from << " " << to << endl; const ll TEN = pow(10, k); Matrix M = zero(3); M[0][0] = TEN; M[0][1] = 1; M[1][1] = 1; M[1][2] = 1; M[2][2] = 1; Array b = Array({0, A + from * B, B}); REP(i, 3) REP(j, 3) M[i][j] %= MOD; REP(i, b.size()) b[i] %= MOD; M = pow(M, n); Array R = mul(M, b); // cout << "k=" << k << ", n="<< n << ", res=" << R[0] << endl; res = (res * mod_pow(TEN % MOD, n, MOD) % MOD + (R[0] % MOD)) % MOD; } return res; } int main2() { ll L, A, B; cin >> L >> A >> B >> MOD; ll ans = solve(A, B, L); cout << ans << endl; return 0; } int main() { // ll A = 1; // ll B = 170; // ll L = 30; // REP(i, L) { // ll s = A + B * i; // cout << getKeta(s) << " " << s << endl; // } // for (int k = 1; k <= 10; k++) { // cout << k << ":" << ketaRange(A, B, L, k) << endl; // } // return 0; #ifdef LOCAL for (; !cin.eof(); cin >> ws) #endif main2(); return 0; }
replace
161
165
161
162
TLE
p03016
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; int Mod; struct Matrix { int n, m; ll a[10][10]; Matrix(int _n = 0, int _m = 0, int x = 0) { memset(a, 0, sizeof a); n = _n, m = _m; for (int i = 1; i <= n; ++i) a[i][i] = x; } Matrix operator*(const Matrix &b) { Matrix res = Matrix(n, b.m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (a[i][j]) for (int k = 1; k <= b.m; ++k) (res.a[i][k] += a[i][j] * b.a[j][k] % Mod) %= Mod; return res; } Matrix operator^(ll k) { Matrix res = Matrix(n, n, 1), x = *this; while (k) { if (k & 1) res = res * x; x = x * x; k >>= 1; } return res; } }; inline ll fsp(ll x, ll k) { x = x % Mod; ll res = 1; while (k) { if (k & 1) res = res * x % Mod; x = x * x % Mod; k >>= 1; } return res; } int main() { freopen("work.in", "r", stdin); freopen("work.out", "w", stdout); ll n, a, d; cin >> n >> a >> d >> Mod; ll b = 1, ans = 0; for (int i = 1; i <= 18; ++i, b = b * 10) { ll L = b, R = 10 * b - 1, s; if (R < a) continue; if (L <= a) L = 1; else L = (L - a - 1) / d + 2; R = (R - a) / d + 1; L = max(L, 1ULL), R = min(R, 1ULL * n); if (L > R) continue; s = (a + (L - 1) * (d)); s %= Mod; Matrix base = Matrix(3, 3, 0); base.a[1][1] = b * 10 % Mod; base.a[2][1] = base.a[2][2] = base.a[3][2] = base.a[3][3] = 1; base = base ^ (R - L + 1); ans = ((ans * fsp(b * 10, (R - L + 1)) % Mod + s % Mod * base.a[2][1] % Mod) % Mod + d % Mod * base.a[3][1] % Mod) % Mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; int Mod; struct Matrix { int n, m; ll a[10][10]; Matrix(int _n = 0, int _m = 0, int x = 0) { memset(a, 0, sizeof a); n = _n, m = _m; for (int i = 1; i <= n; ++i) a[i][i] = x; } Matrix operator*(const Matrix &b) { Matrix res = Matrix(n, b.m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (a[i][j]) for (int k = 1; k <= b.m; ++k) (res.a[i][k] += a[i][j] * b.a[j][k] % Mod) %= Mod; return res; } Matrix operator^(ll k) { Matrix res = Matrix(n, n, 1), x = *this; while (k) { if (k & 1) res = res * x; x = x * x; k >>= 1; } return res; } }; inline ll fsp(ll x, ll k) { x = x % Mod; ll res = 1; while (k) { if (k & 1) res = res * x % Mod; x = x * x % Mod; k >>= 1; } return res; } int main() { ll n, a, d; cin >> n >> a >> d >> Mod; ll b = 1, ans = 0; for (int i = 1; i <= 18; ++i, b = b * 10) { ll L = b, R = 10 * b - 1, s; if (R < a) continue; if (L <= a) L = 1; else L = (L - a - 1) / d + 2; R = (R - a) / d + 1; L = max(L, 1ULL), R = min(R, 1ULL * n); if (L > R) continue; s = (a + (L - 1) * (d)); s %= Mod; Matrix base = Matrix(3, 3, 0); base.a[1][1] = b * 10 % Mod; base.a[2][1] = base.a[2][2] = base.a[3][2] = base.a[3][3] = 1; base = base ^ (R - L + 1); ans = ((ans * fsp(b * 10, (R - L + 1)) % Mod + s % Mod * base.a[2][1] % Mod) % Mod + d % Mod * base.a[3][1] % Mod) % Mod; } cout << ans << endl; return 0; }
delete
52
54
52
52
-8
p03016
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define popcount __builtin_popcount using namespace std; typedef long long ll; typedef pair<int, int> P; typedef __int128_t lll; ll MOD; ll powmod(ll a, lll k) { ll ap = a, ans = 1; while (k) { if (k & 1) { ans *= ap; ans %= MOD; } ap = ap * ap; ap %= MOD; k >>= 1; } return ans; } vector<vector<ll>> matrixmul(int l, int m, int n, vector<vector<ll>> a, vector<vector<ll>> b) { vector<vector<ll>> c; for (int i = 0; i < l; i++) { vector<ll> v; for (int j = 0; j < n; j++) { ll x = 0; for (int k = 0; k < m; k++) { x += (a[i][k] * b[k][j]); x %= MOD; } v.push_back(x); } c.push_back(v); } return c; } vector<vector<ll>> matrixpow(int n, vector<vector<ll>> a, ll k) { vector<vector<ll>> ap = a, ans; for (int i = 0; i < n; i++) { vector<ll> v; for (int j = 0; j < n; j++) { if (i == j) { v.push_back(1); } else { v.push_back(0); } } ans.push_back(v); } while (k) { if (k & 1) ans = matrixmul(n, n, n, ap, ans); ap = matrixmul(n, n, n, ap, ap); k >>= 1; } return ans; } int main() { ll l, a, b; cin >> l >> a >> b >> MOD; ll p = 1; ll cnt[20] = {}; ll s[20] = {}; for (int i = 0; i < 18; i++) { ll x = (p - a + b - 1) / b, y = (10 * p - a + b - 1) / b; if (x >= l || 10 * p - a <= 0) { p *= 10; continue; } y = min(y, l); x = max(0ll, x); if (x == y) { p *= 10; continue; } cnt[i] = y - x; vector<vector<ll>> mat; vector<ll> v[3]; v[0].resize(3); v[0][0] = 10 * p % MOD, v[0][1] = 1, v[0][2] = b % MOD; mat.push_back(v[0]); v[1].resize(3); v[1][0] = 0, v[1][1] = 1, v[1][2] = b % MOD; mat.push_back(v[1]); v[2].resize(3); v[2][1] = 0, v[2][2] = 1, v[2][0] = 0; mat.push_back(v[2]); vector<vector<ll>> mp = matrixpow(3, mat, y - x - 1); ll a1 = a + x * b; s[i] = (mp[0][0] * (a1 % MOD) + mp[0][1] * (a1 % MOD) + mp[0][2]) % MOD; p *= 10; } // for(int i=0; i<18; i++) cout<<cnt[i]<<endl; // cout<<cnt[0]<<" "<<cnt[1]<<" "<<s[0]<<" "<<s[1]<<endl; ll ans = 0; lll c = 0; for (int i = 17; i >= 0; i--) { ans += s[i] * powmod(10, c) % MOD; c += cnt[i] * (ll)(i + 1); ans %= MOD; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define popcount __builtin_popcount using namespace std; typedef long long ll; typedef pair<int, int> P; typedef __int128_t lll; ll MOD; ll powmod(ll a, lll k) { ll ap = a, ans = 1; while (k) { if (k & 1) { ans *= ap; ans %= MOD; } ap = ap * ap; ap %= MOD; k >>= 1; } return ans; } vector<vector<ll>> matrixmul(int l, int m, int n, vector<vector<ll>> a, vector<vector<ll>> b) { vector<vector<ll>> c; for (int i = 0; i < l; i++) { vector<ll> v; for (int j = 0; j < n; j++) { ll x = 0; for (int k = 0; k < m; k++) { x += (a[i][k] * b[k][j]); x %= MOD; } v.push_back(x); } c.push_back(v); } return c; } vector<vector<ll>> matrixpow(int n, vector<vector<ll>> a, ll k) { vector<vector<ll>> ap = a, ans; for (int i = 0; i < n; i++) { vector<ll> v; for (int j = 0; j < n; j++) { if (i == j) { v.push_back(1); } else { v.push_back(0); } } ans.push_back(v); } while (k) { if (k & 1) ans = matrixmul(n, n, n, ap, ans); ap = matrixmul(n, n, n, ap, ap); k >>= 1; } return ans; } int main() { ll l, a, b; cin >> l >> a >> b >> MOD; ll p = 1; ll cnt[20] = {}; ll s[20] = {}; for (int i = 0; i < 18; i++) { ll x = (p - a + b - 1) / b, y = (10 * p - a + b - 1) / b; if (x >= l || 10 * p - a <= 0) { p *= 10; continue; } y = min(y, l); x = max(0ll, x); if (x == y) { p *= 10; continue; } cnt[i] = y - x; vector<vector<ll>> mat; vector<ll> v[3]; v[0].resize(3); v[0][0] = 10 * p % MOD, v[0][1] = 1, v[0][2] = b % MOD; mat.push_back(v[0]); v[1].resize(3); v[1][0] = 0, v[1][1] = 1, v[1][2] = b % MOD; mat.push_back(v[1]); v[2].resize(3); v[2][1] = 0, v[2][2] = 1, v[2][0] = 0; mat.push_back(v[2]); vector<vector<ll>> mp = matrixpow(3, mat, y - x - 1); ll a1 = a + x * b; s[i] = (mp[0][0] * (a1 % MOD) + mp[0][1] * (a1 % MOD) + mp[0][2]) % MOD; p *= 10; } // for(int i=0; i<18; i++) cout<<cnt[i]<<endl; // cout<<cnt[0]<<" "<<cnt[1]<<" "<<s[0]<<" "<<s[1]<<endl; ll ans = 0; lll c = 0; for (int i = 17; i >= 0; i--) { ans += s[i] * powmod(10, c) % MOD; c += (lll)cnt[i] * (lll)(i + 1); ans %= MOD; } cout << ans << endl; return 0; }
replace
116
117
116
117
TLE
p03016
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define mod 1000000007 #define mad(a, b) a = (a + b) % mod #define Nmax 55 ll mo; ll po(ll x, ll y) { if (y < 0) cout << 1 / 0 << endl; ll res = 1; for (; y; y >>= 1) { if (y & 1) res = res * x; x = x * x; } return res; } ll pomo(ll x, ll y) { if (y < 0) cout << 1 / 0 << endl; ll res = 1; for (; y; y >>= 1) { if (y & 1) res = res * x % mo; x = x * x % mo; } return res; } struct matrix { ll t[3][3]; }; matrix mul(matrix a, matrix b) { matrix c; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { ll res = 0; for (int k = 0; k < 3; k++) { res += a.t[i][k] * b.t[k][j]; } c.t[i][j] = res % mo; } return c; } ll solve(ll d, ll a, ll b, ll l) { matrix r[66]; ll kei[] = {1, b % mo, 0, 0, po(10, d) % mo, 0, 1, a % mo, 1}; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { r[0].t[i][j] = kei[i * 3 + j]; } for (int i = 1; i < 62; i++) r[i] = mul(r[i - 1], r[i - 1]); matrix res; bool fi = 1; for (int i = 0; i < 62; i++) { if ((1LL << i) & l) { if (fi) res = r[i], fi = 0; else res = mul(res, r[i]); } } return res.t[2][1]; } int main() { cin.tie(0); ios::sync_with_stdio(0); ll l, a, b; cin >> l >> a >> b >> mo; ll ans = 0; ll ruiketa = 1; for (int d = 18; d >= 1; d--) { if (po(10, d) <= a) continue; if (a + b * (l - 1) < po(10, d - 1)) continue; ll s = a; if (s < po(10, d - 1)) s = a + (po(10, d - 1) - 1 - a + b) / b * b; ll t = a + b * (l - 1); if (po(10, d) <= t) t = a + (po(10, d) - 1 - a) / b * b; ll len = (t - s) / b + 1; if (len > 0) { ll res = solve(d, s, b, len); // cout<<d<<" "<<s<<" "<<b<<" "<<len<<" "<<res<<endl; ans = ans + ruiketa * res; ans %= mo; ruiketa = ruiketa * pomo(10, len * d) % mo; } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define mod 1000000007 #define mad(a, b) a = (a + b) % mod #define Nmax 55 ll mo; ll po(ll x, ll y) { if (y < 0) cout << 1 / 0 << endl; ll res = 1; for (; y; y >>= 1) { if (y & 1) res = res * x; x = x * x; } return res; } ll pomo(ll x, ll y) { if (y < 0) cout << 1 / 0 << endl; ll res = 1; for (; y; y >>= 1) { if (y & 1) res = res * x % mo; x = x * x % mo; } return res; } struct matrix { ll t[3][3]; }; matrix mul(matrix a, matrix b) { matrix c; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { ll res = 0; for (int k = 0; k < 3; k++) { res += a.t[i][k] * b.t[k][j]; } c.t[i][j] = res % mo; } return c; } ll solve(ll d, ll a, ll b, ll l) { matrix r[66]; ll kei[] = {1, b % mo, 0, 0, po(10, d) % mo, 0, 1, a % mo, 1}; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { r[0].t[i][j] = kei[i * 3 + j]; } for (int i = 1; i < 62; i++) r[i] = mul(r[i - 1], r[i - 1]); matrix res; bool fi = 1; for (int i = 0; i < 62; i++) { if ((1LL << i) & l) { if (fi) res = r[i], fi = 0; else res = mul(res, r[i]); } } return res.t[2][1]; } int main() { cin.tie(0); ios::sync_with_stdio(0); ll l, a, b; cin >> l >> a >> b >> mo; ll ans = 0; ll ruiketa = 1; for (int d = 18; d >= 1; d--) { if (po(10, d) <= a) continue; if (a + b * (l - 1) < po(10, d - 1)) continue; ll s = a; if (s < po(10, d - 1)) s = a + (po(10, d - 1) - 1 - a + b) / b * b; ll t = a + b * (l - 1); if (po(10, d) <= t) t = a + (po(10, d) - 1 - a) / b * b; ll len = (t - s) / b + 1; if (len > 0) { ll res = solve(d, s, b, len); // cout<<d<<" "<<s<<" "<<b<<" "<<len<<" "<<res<<endl; ans = ans + ruiketa * res; ans %= mo; ruiketa = ruiketa * pomo(pomo(10, len), d) % mo; } } cout << ans << endl; }
replace
100
101
100
101
0
p03016
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define db double #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define mat vector<vector<ll>> const int inf = 1 << 30; const ll linf = 1e18; const db EPS = 1e-7; template <class T> void chmin(T &x, T y) { if (x > y) x = y; } template <class T> void chmax(T &x, T y) { if (x < y) x = y; } ll L, A, B, M; mat mat_mul(const mat &m1, const mat &m2) { mat res = {}; for (int i = 0; i + 1 < m1.size(); ++i) { if (m1[i].size() != m1[i + 1].size()) return res; } for (int i = 0; i + 1 < m2.size(); ++i) { if (m2[i].size() != m2[i + 1].size()) return res; } if (m1[0].size() != m2.size()) return res; int n = m1.size(), m = m2[0].size(); res = mat(n, vector<ll>(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < m1[0].size(); k++) { res[i][j] += m1[i][k] * m2[k][j]; res[i][j] %= M; } } } return res; } mat dia_mat(int sz) { mat res = mat(sz, vector<ll>(sz, 0)); for (int i = 0; i < sz; i++) res[i][i] = 1; return res; } mat mat_pow(mat m, ll exp) { mat res = dia_mat(m.size()); while (exp > 0) { if (exp % 2) { res = mat_mul(res, m); } m = mat_mul(m, m); exp /= 2; res[0][0] %= M; m[0][0] %= M; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> L >> A >> B >> M; int cnt = 0; mat m1 = {{0, A, 1}}; ll d = 1; while (cnt < L) { auto culc = [](ll num) -> ll { if (num < A) return 0; else return ((num - A) / B) + 1; }; ll cnt2 = culc(d * 10 - 1); cnt2 -= culc(d - 1); if (cnt + cnt2 > L) cnt2 = L - cnt; cnt += cnt2; d *= 10; mat m2 = {{d % M, 0, 0}, {1, 1, 0}, {0, B, 1}}; mat m3 = mat_pow(m2, cnt2); m1 = mat_mul(m1, m3); m1[0][0] %= M; } cout << m1[0][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define db double #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define mat vector<vector<ll>> const int inf = 1 << 30; const ll linf = 1e18; const db EPS = 1e-7; template <class T> void chmin(T &x, T y) { if (x > y) x = y; } template <class T> void chmax(T &x, T y) { if (x < y) x = y; } ll L, A, B, M; mat mat_mul(const mat &m1, const mat &m2) { mat res = {}; for (int i = 0; i + 1 < m1.size(); ++i) { if (m1[i].size() != m1[i + 1].size()) return res; } for (int i = 0; i + 1 < m2.size(); ++i) { if (m2[i].size() != m2[i + 1].size()) return res; } if (m1[0].size() != m2.size()) return res; int n = m1.size(), m = m2[0].size(); res = mat(n, vector<ll>(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < m1[0].size(); k++) { res[i][j] += m1[i][k] * m2[k][j]; res[i][j] %= M; } } } return res; } mat dia_mat(int sz) { mat res = mat(sz, vector<ll>(sz, 0)); for (int i = 0; i < sz; i++) res[i][i] = 1; return res; } mat mat_pow(mat m, ll exp) { mat res = dia_mat(m.size()); while (exp > 0) { if (exp % 2) { res = mat_mul(res, m); } m = mat_mul(m, m); exp /= 2; res[0][0] %= M; m[0][0] %= M; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> L >> A >> B >> M; ll cnt = 0; mat m1 = {{0, A, 1}}; ll d = 1; while (cnt < L) { auto culc = [](ll num) -> ll { if (num < A) return 0; else return ((num - A) / B) + 1; }; ll cnt2 = culc(d * 10 - 1); cnt2 -= culc(d - 1); if (cnt + cnt2 > L) cnt2 = L - cnt; cnt += cnt2; d *= 10; mat m2 = {{d % M, 0, 0}, {1, 1, 0}, {0, B, 1}}; mat m3 = mat_pow(m2, cnt2); m1 = mat_mul(m1, m3); m1[0][0] %= M; } cout << m1[0][0] << endl; return 0; }
replace
77
78
77
78
TLE
p03017
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int main() { ll n, a, b, c, d; cin >> n >> a >> b >> c >> d; a--; b--; c--; d--; string s; cin >> s; bool ans = true; s[n] = '#'; for (ll i = b; i <= d; i++) { if (s[i] == '#' && s[i + 1] == '#') { ans = false; break; } for (ll i = a; i <= c; i++) { if (s[i] == '#' && s[i + 1] == '#') { ans = false; break; } } } if (c > d) { ans = false; for (ll i = b; i <= d; i++) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { ans = true; } } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int main() { ll n, a, b, c, d; cin >> n >> a >> b >> c >> d; a--; b--; c--; d--; string s; cin >> s; bool ans = true; s[n] = '#'; for (ll i = b; i <= d; i++) { if (s[i] == '#' && s[i + 1] == '#') { ans = false; break; } } for (ll i = a; i <= c; i++) { if (s[i] == '#' && s[i + 1] == '#') { ans = false; break; } } if (c > d) { ans = false; for (ll i = b; i <= d; i++) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { ans = true; } } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
replace
21
26
21
26
TLE
p03017
C++
Runtime Error
#include <algorithm> #include <cassert> #include <chrono> #include <cstring> #include <ctime> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; const int MAXN = 100000; char s[1 + MAXN]; bool dpa[1 + MAXN], dpb[1 + MAXN], dpc[1 + MAXN], dpd[1 + MAXN]; void dodp(int n, int x, bool *dp) { dp[x] = true; for (int i = x + 1; i <= n; i++) dp[i] = (s[i] != '#') && (dp[i - 1] || dp[i - 2]); for (int i = x - 1; i >= 1; i--) dp[i] = (s[i] != '#') && (dp[i + 1] || dp[i + 2]); } void print(bool answer) { if (answer) cout << "Yes\n"; else cout << "No\n"; } int main() { // ifstream cin("input.in"); int n, a, b, c, d; cin >> n >> a >> b >> c >> d >> (s + 1); dodp(n, a, dpa); dodp(n, b, dpb); dodp(n, c, dpc); dodp(n, d, dpd); if (c < d) print(dpa[c] && dpb[d]); else { for (int i = b; i <= d; i++) if (dpb[i] && dpd[i] && dpa[i - 1] && dpc[i + 1]) { print(true); return 0; } print(false); } return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <cstring> #include <ctime> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; const int MAXN = 200000; char s[1 + MAXN]; bool dpa[1 + MAXN], dpb[1 + MAXN], dpc[1 + MAXN], dpd[1 + MAXN]; void dodp(int n, int x, bool *dp) { dp[x] = true; for (int i = x + 1; i <= n; i++) dp[i] = (s[i] != '#') && (dp[i - 1] || dp[i - 2]); for (int i = x - 1; i >= 1; i--) dp[i] = (s[i] != '#') && (dp[i + 1] || dp[i + 2]); } void print(bool answer) { if (answer) cout << "Yes\n"; else cout << "No\n"; } int main() { // ifstream cin("input.in"); int n, a, b, c, d; cin >> n >> a >> b >> c >> d >> (s + 1); dodp(n, a, dpa); dodp(n, b, dpb); dodp(n, c, dpc); dodp(n, d, dpd); if (c < d) print(dpa[c] && dpb[d]); else { for (int i = b; i <= d; i++) if (dpb[i] && dpd[i] && dpa[i - 1] && dpc[i + 1]) { print(true); return 0; } print(false); } return 0; }
replace
16
17
16
17
0
p03017
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX typedef long long ll; using namespace std; int main() { ll n, a, b, c, d; cin >> n >> a >> b >> c >> d; string s, res; cin >> s; ll m = max(c, d); int x = 0; for (ll i = a; i < m; i++) { if (s.at(i) == '#' && x) { res = "No"; cout << res << endl; return 0; } if (s.at(i) == '#') { x = 1; } else { x = 0; } } if (c < d) { res = "Yes"; cout << res << endl; } else { for (ll i = b - 2; i < d; i++) { if (s.at(i) == '.' && s.at(i + 1) == '.' && s.at(i + 2) == '.') { res = "Yes"; cout << res << endl; return 0; } } res = "No"; cout << res << endl; } return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX typedef long long ll; using namespace std; int main() { ll n, a, b, c, d; cin >> n >> a >> b >> c >> d; string s, res; cin >> s; ll m = max(c, d); int x = 0; for (ll i = a; i < m; i++) { if (s.at(i) == '#' && x) { res = "No"; cout << res << endl; return 0; } if (s.at(i) == '#') { x = 1; } else { x = 0; } } if (c < d) { res = "Yes"; cout << res << endl; } else { for (ll i = b - 1; i < d; i++) { if (s.at(i - 1) == '.' && s.at(i) == '.' && s.at(i + 1) == '.') { res = "Yes"; cout << res << endl; return 0; } } res = "No"; cout << res << endl; } return 0; }
replace
40
42
40
42
0
p03017
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, x, y) for (int i = x; i < y; i++) #define range(a) a.begin(), a.end() int main() { int N, A, B, C, D; cin >> N >> A >> B >> C >> D; string S; cin >> S; if (C < D) { bool flag = true; rep(i, A - 1, C - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag = false; break; } } rep(i, B - 1, D - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag = false; break; } } if (flag == true) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { bool flag1 = true; rep(i, A - 1, C - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag1 = false; break; } } bool flag2 = false; int a, b, c; a = S.at(B - 2); b = S.at(B - 1); c = S.at(B); rep(i, B - 2, D - 1) { if (a == '.' && b == '.' && c == '.') { flag2 = true; break; } a = b; b = c; c = S.at(i + 3); } if (flag1 == true && flag2 == true) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, x, y) for (int i = x; i < y; i++) #define range(a) a.begin(), a.end() int main() { int N, A, B, C, D; cin >> N >> A >> B >> C >> D; string S; cin >> S; if (C < D) { bool flag = true; rep(i, A - 1, C - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag = false; break; } } rep(i, B - 1, D - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag = false; break; } } if (flag == true) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { bool flag1 = true; rep(i, A - 1, C - 2) { if (S.at(i) == '#' && S.at(i + 1) == '#') { flag1 = false; break; } } bool flag2 = false; int a, b, c; a = S.at(B - 2); b = S.at(B - 1); c = S.at(B); rep(i, B - 2, D - 1) { if (a == '.' && b == '.' && c == '.') { flag2 = true; break; } a = b; b = c; if (i != D - 2) c = S.at(i + 3); } if (flag1 == true && flag2 == true) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
replace
48
49
48
50
0
p03017
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; #define FI(i, a, b) for (int i = (a); i <= (b); ++i) #define FD(i, b, a) for (int i = (b); i >= (a); --i) #define DEBUG(x) cerr << #x << ": " << (x) << endl; int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; string s; cin >> n >> s; s = " " + s; auto check = [&](int l, int r) { if (s[l] == '#' || s[r] == '#') return false; for (int i = l + 1; i <= r; i++) { if (s[i] == '#' && s[i - 1] == '#') return false; } return true; }; if (c == d) return puts("No"), 0; if (c < d) { if (check(b, d) && check(a, c)) puts("Yes"); else puts("No"); return 0; } else { if (!check(b, d) || !check(a, c)) return puts("No"), 0; for (int i = b; i <= d; i++) { if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') return puts("Yes"), 0; // puts("N"); } puts("No"); } }
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; #define FI(i, a, b) for (int i = (a); i <= (b); ++i) #define FD(i, b, a) for (int i = (b); i >= (a); --i) #define DEBUG(x) cerr << #x << ": " << (x) << endl; int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; string s; cin >> s; s = " " + s; auto check = [&](int l, int r) { if (s[l] == '#' || s[r] == '#') return false; for (int i = l + 1; i <= r; i++) { if (s[i] == '#' && s[i - 1] == '#') return false; } return true; }; if (c == d) return puts("No"), 0; if (c < d) { if (check(b, d) && check(a, c)) puts("Yes"); else puts("No"); return 0; } else { if (!check(b, d) || !check(a, c)) return puts("No"), 0; for (int i = b; i <= d; i++) { if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') return puts("Yes"), 0; // puts("N"); } puts("No"); } }
replace
12
13
12
13
0
p03017
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; int Max = 1000000; int N; int A, B, C, D; string S; bool possi(int a, int b) { bool res = true; for (int i = a + 1; i < b; i++) { if (S[i] == S[i + 1] && S[i + 1] == '#') res = false; } return res; } int main() { cin >> N; cin >> A >> B >> C >> D; string S; cin >> S; if (C == D) { cout << "No" << endl; return 0; } if (C < D) { if (possi(B - 1, D - 1) && possi(A - 1, C - 1)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } if (!possi(B - 1, D - 1)) { // cout << 1 << endl; cout << "No" << endl; return 0; } if (!possi(A - 1, C - 1)) { // cout << 2 << endl; cout << "No" << endl; return 0; } for (int i = B - 1; i < D; i++) { if (S[i] == '.' && S[i - 1] == '.' && S[i + 1] == '.') { // cout << 3 << endl; cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; int Max = 1000000; int N; int A, B, C, D; string S; bool possi(int a, int b) { bool res = true; for (int i = a + 1; i < b; i++) { if (S[i] == S[i + 1] && S[i + 1] == '#') res = false; } return res; } int main() { cin >> N; cin >> A >> B >> C >> D; cin >> S; if (C == D) { cout << "No" << endl; return 0; } if (C < D) { if (possi(B - 1, D - 1) && possi(A - 1, C - 1)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } if (!possi(B - 1, D - 1)) { // cout << 1 << endl; cout << "No" << endl; return 0; } if (!possi(A - 1, C - 1)) { // cout << 2 << endl; cout << "No" << endl; return 0; } for (int i = B - 1; i < D; i++) { if (S[i] == '.' && S[i - 1] == '.' && S[i + 1] == '.') { // cout << 3 << endl; cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
delete
24
25
24
24
0
p03017
Python
Runtime Error
# https://atcoder.jp/contests/agc034/tasks/agc034_a import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n, a, b, c, d = input_int_list() S = input() for i in range(a - 1, max(c, d) - 1): if S[i] == S[i + 1] == "#": print("No") quit() if c < d: print("Yes") quit() if c > d: for i in range(b - 2, d - 1): if S[i, i + 3] == "...": print("Yes") quit() print("No") quit() if __name__ == "__main__": main()
# https://atcoder.jp/contests/agc034/tasks/agc034_a import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n, a, b, c, d = input_int_list() S = input() for i in range(a - 1, max(c, d) - 1): if S[i] == S[i + 1] == "#": print("No") quit() if c < d: print("Yes") quit() if c > d: for i in range(b - 2, d - 1): if S[i : i + 3] == "...": print("Yes") quit() print("No") quit() if __name__ == "__main__": main()
replace
32
33
32
33
0
p03017
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; a--; b--; c--; d--; string s; cin >> s; if (c < d) { for (int i = b + 1; i < d; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; } else { // bがdまでいけない for (int i = b + 1; i < d; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } // bを先に動かすとき bool flag1 = false; for (int i = b; i <= d;) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { flag1 = true; } } // aがcまでいけない for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { flag1 = false; } } // aを先に動かすとき bool flag2 = true; // aがcまでいけない s[b] = '#'; for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { flag2 = false; } } if (flag2 || flag1) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; a--; b--; c--; d--; string s; cin >> s; if (c < d) { for (int i = b + 1; i < d; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; } else { // bがdまでいけない for (int i = b + 1; i < d; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { cout << "No" << endl; return 0; } } // bを先に動かすとき bool flag1 = false; for (int i = b; i <= d; i++) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { flag1 = true; } } // aがcまでいけない for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { flag1 = false; } } // aを先に動かすとき bool flag2 = true; // aがcまでいけない s[b] = '#'; for (int i = a + 1; i < c; i++) { char c = s[i]; if (s[i + 1] == '#' && c == '#') { flag2 = false; } } if (flag2 || flag1) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } }
replace
65
66
65
66
TLE
p03017
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int)x.size()) #define fast_io \ ios_base::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; string s; bool can_reach(int p, int q) { while (p != q) { if (p + 1 <= q && s[p + 1] != '#') { p++; } else if (p + 2 <= q && s[p + 2] != '#') { p += 2; } } return p == q; } bool can_cross(int p, int q) { for (int i = p; i + 2 <= q; i++) { if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') { return 1; } } return 0; } int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d >> s; a--; b--; c--; d--; if (can_reach(a, c) && can_reach(b, d) && c < d) { cout << "Yes" << endl; } else if (c > d && can_reach(a, c) && can_reach(b, d) && can_cross(b - 1, d + 1)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int)x.size()) #define fast_io \ ios_base::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; string s; bool can_reach(int p, int q) { while (p != q) { if (p + 1 <= q && s[p + 1] != '#') { p++; } else if (p + 2 <= q && s[p + 2] != '#') { p += 2; } else { break; } } return p == q; } bool can_cross(int p, int q) { for (int i = p; i + 2 <= q; i++) { if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') { return 1; } } return 0; } int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d >> s; a--; b--; c--; d--; if (can_reach(a, c) && can_reach(b, d) && c < d) { cout << "Yes" << endl; } else if (c > d && can_reach(a, c) && can_reach(b, d) && can_cross(b - 1, d + 1)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
insert
16
16
16
18
TLE
p03017
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool check(int start, int end, string S) { for (int i = start; i <= end; i++) { if (i + 1 == end || i == end - 1) break; if (S.at(i + 1) == '#') { if (S.at(i + 2) == '#') { cout << "No" << endl; return 0; } else { i++; } } } return 1; } bool cannot_pass(string S, int b, int d) { for (int i = b - 1; i <= (d - 2) + 1; i++) { if (S.at(i) == S.at(i + 1) && S.at(i + 1) == S.at(i + 2) && S.at(i) == '.') return 0; } return 1; } int main() { int N, a, b, c, d; string S; cin >> N >> a >> b >> c >> d >> S; if (check(b - 1, d - 1, S) && check(a - 1, c - 1, S)) { if (d < c && cannot_pass(S, b - 1, d - 1)) { cout << "No" << endl; return 0; } cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; bool check(int start, int end, string S) { for (int i = start; i <= end; i++) { if (i + 1 == end || i + 2 == end) break; if (S.at(i + 1) == '#') { if (S.at(i + 2) == '#') { cout << "No" << endl; return 0; } else { i++; } } } return 1; } bool cannot_pass(string S, int b, int d) { for (int i = b - 1; i <= (d - 2) + 1; i++) { if (S.at(i) == S.at(i + 1) && S.at(i + 1) == S.at(i + 2) && S.at(i) == '.') return 0; } return 1; } int main() { int N, a, b, c, d; string S; cin >> N >> a >> b >> c >> d >> S; if (check(b - 1, d - 1, S) && check(a - 1, c - 1, S)) { if (d < c && cannot_pass(S, b - 1, d - 1)) { cout << "No" << endl; return 0; } cout << "Yes" << endl; } }
replace
5
6
5
6
0
p03017
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using vint = vector<int>; using vvint = vector<vint>; using vvvint = vector<vvint>; using vdouble = vector<double>; using vvdouble = vector<vdouble>; using vvvdouble = vector<vvdouble>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using uint = unsigned int; using ull = unsigned long long; template <typename T> using uset = unordered_set<T>; template <typename T1, typename T2> using umap = unordered_map<T1, T2>; constexpr int INF = (1 << 30) - 1; constexpr ll LLINF = 1LL << 60; constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr char el = '\n'; constexpr int mod = 1000000007; template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); } template <typename T> bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); } template <typename T> bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); i++) os << " " << v[i]; return (os); } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &u : v) is >> u; return (is); } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return (is >> p.first >> p.second); } int N; string S; int check(int from) { int right = -1; for (int i = from + 2; i < N; i++) { if (S[i] == '#' && S[i - 1] == '#') { right = i - 2; break; } } if (right == -1) right = N - 1 - (int)(S[N - 1] == '#'); return (right); } void Main() { int A, B, C, D; cin >> N >> A >> B >> C >> D; --A, --B, --C, --D; cin >> S; int ad = check(A); int bd = check(B); if (C <= ad && D <= bd) { if (C > D) { abort(); for (int i = B + 1; i < D; i++) { if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') { cout << "Yes" << endl; return; } } cout << "No" << endl; } else { cout << "Yes" << endl; } } else { cout << "No" << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); Main(); return (0); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using vint = vector<int>; using vvint = vector<vint>; using vvvint = vector<vvint>; using vdouble = vector<double>; using vvdouble = vector<vdouble>; using vvvdouble = vector<vvdouble>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using uint = unsigned int; using ull = unsigned long long; template <typename T> using uset = unordered_set<T>; template <typename T1, typename T2> using umap = unordered_map<T1, T2>; constexpr int INF = (1 << 30) - 1; constexpr ll LLINF = 1LL << 60; constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr char el = '\n'; constexpr int mod = 1000000007; template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); } template <typename T> bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); } template <typename T> bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); i++) os << " " << v[i]; return (os); } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &u : v) is >> u; return (is); } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return (is >> p.first >> p.second); } int N; string S; int check(int from) { int right = -1; for (int i = from + 2; i < N; i++) { if (S[i] == '#' && S[i - 1] == '#') { right = i - 2; break; } } if (right == -1) right = N - 1 - (int)(S[N - 1] == '#'); return (right); } void Main() { int A, B, C, D; cin >> N >> A >> B >> C >> D; --A, --B, --C, --D; cin >> S; int ad = check(A); int bd = check(B); if (C <= ad && D <= bd) { if (C > D) { for (int i = B; i <= D; i++) { if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') { cout << "Yes" << endl; return; } } cout << "No" << endl; } else { cout << "Yes" << endl; } } else { cout << "No" << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); Main(); return (0); }
replace
86
88
86
87
0
p03017
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; ll n, a, b, c, d; string str; bool check(ll l, ll r) { ll i = l; while (i < r) { if ((i + 1) < n && str[i + 1] == '.') i++; else if ((i + 2) < n && str[i + 2] == '.') i += 2; } if (i == r) return true; return false; } int main() { cin >> n >> a >> b >> c >> d; cin >> str; a--; b--; c--; d--; vector<bool> flg(n + 1, false); if (check(a, c) && check(b, d)) { if (c < d) cout << "Yes"; else { ll i = a; flg[i] = true; while (i < c) { if ((i + 1) != c && (i + 2) < n && str[i + 2] == '.') { i += 2; flg[i] = true; } else if ((i + 1) < n && str[i + 1] == '.') { i += 1; flg[i] = true; } } i = b; ll tmp_flg = 0; while (i < d) { if ((i + 1) < n && str[i + 1] == '.') { if (flg[i] == false || flg[i + 1] == false) { tmp_flg = 1; break; } i += 1; } else if ((i + 2) < n && str[i + 2] == '.') { if (flg[i] == false || flg[i + 2] == false) { tmp_flg = 1; break; } i += 2; } } if (tmp_flg) cout << "Yes"; else cout << "No"; } } else cout << "No"; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; ll n, a, b, c, d; string str; bool check(ll l, ll r) { ll i = l; while (i < r) { if ((i + 1) < n && str[i + 1] == '.') i++; else if ((i + 2) < n && str[i + 2] == '.') i += 2; else break; } if (i == r) return true; return false; } int main() { cin >> n >> a >> b >> c >> d; cin >> str; a--; b--; c--; d--; vector<bool> flg(n + 1, false); if (check(a, c) && check(b, d)) { if (c < d) cout << "Yes"; else { ll i = a; flg[i] = true; while (i < c) { if ((i + 1) != c && (i + 2) < n && str[i + 2] == '.') { i += 2; flg[i] = true; } else if ((i + 1) < n && str[i + 1] == '.') { i += 1; flg[i] = true; } } i = b; ll tmp_flg = 0; while (i < d) { if ((i + 1) < n && str[i + 1] == '.') { if (flg[i] == false || flg[i + 1] == false) { tmp_flg = 1; break; } i += 1; } else if ((i + 2) < n && str[i + 2] == '.') { if (flg[i] == false || flg[i + 2] == false) { tmp_flg = 1; break; } i += 2; } } if (tmp_flg) cout << "Yes"; else cout << "No"; } } else cout << "No"; return 0; }
insert
14
14
14
16
TLE
p03017
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define fr(i, a, b) for (ll i = a; i < b; i++) #define pb(v, a) v.push_back(a) #define Sort(v) sort(v.begin(), v.end()) #define For(m) for (auto it = m.begin(); it != m.end(); it++) #define mp(p1, p2) make_pair(p1, p2) #define mod 1000000007 #define PI 3.14159265358979323846 #define pii pair<ll, ll> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast ll n; cin >> n; ll a; cin >> a; ll b; cin >> b; ll c; cin >> c; ll d; cin >> d; string s; cin >> s; fr(i, b - 1, d) { if (s[i] == '#' && s[i - 1] == '#') { cout << "No"; return 0; } } fr(i, a - 1, c) { if (s[i] == '#' && s[i - 1] == '#') { cout << "No"; return 0; } } if (c > d) { bool ans = false; if (s[b] == '.' && s[b - 2] == '.') ans = true; fr(i, b + 1, d) { if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') ans = true; } if (s[d] == '.' && s[d - 2] == '.') ans = true; if (ans) { cout << "Yes"; } else cout << "No"; return 0; } cout << "Yes"; return 0; }
#include <bits/stdc++.h> #define ll long long int #define fr(i, a, b) for (ll i = a; i < b; i++) #define pb(v, a) v.push_back(a) #define Sort(v) sort(v.begin(), v.end()) #define For(m) for (auto it = m.begin(); it != m.end(); it++) #define mp(p1, p2) make_pair(p1, p2) #define mod 1000000007 #define PI 3.14159265358979323846 #define pii pair<ll, ll> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif fast ll n; cin >> n; ll a; cin >> a; ll b; cin >> b; ll c; cin >> c; ll d; cin >> d; string s; cin >> s; fr(i, b - 1, d) { if (s[i] == '#' && s[i - 1] == '#') { cout << "No"; return 0; } } fr(i, a - 1, c) { if (s[i] == '#' && s[i - 1] == '#') { cout << "No"; return 0; } } if (c > d) { bool ans = false; if (s[b] == '.' && s[b - 2] == '.') ans = true; fr(i, b + 1, d) { if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') ans = true; } if (s[d] == '.' && s[d - 2] == '.') ans = true; if (ans) { cout << "Yes"; } else cout << "No"; return 0; } cout << "Yes"; return 0; }
replace
17
21
17
21
-11
p03017
C++
Runtime Error
#include <iostream> #include <string> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) bool judge(int a, int b, string s) { for (int i = a - 1; i < b - 1; i++) { if (s[i] == '#' && s[i + 1] == '#') { return false; } } return true; } bool check(int a, int b, string s) { for (int i = a - 1; i <= b - 1; i++) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { return true; } } return false; } int main() { int n, a, b, c, d; cin >> a >> b >> c >> d; string s; cin >> s; if (judge(a, c, s) && judge(b, d, s)) { if (c < d || check(b, d, s)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { cout << "No" << endl; } }
#include <iostream> #include <string> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) bool judge(int a, int b, string s) { for (int i = a - 1; i < b - 1; i++) { if (s[i] == '#' && s[i + 1] == '#') { return false; } } return true; } bool check(int a, int b, string s) { for (int i = a - 1; i <= b - 1; i++) { if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') { return true; } } return false; } int main() { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; string s; cin >> s; if (judge(a, c, s) && judge(b, d, s)) { if (c < d || check(b, d, s)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { cout << "No" << endl; } }
replace
22
23
22
23
0
p03017
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define pb push_back #define mk make_pair #define eps 1e-8 #define fi first #define se second #define all(x) (x).begin(), (x).end() using namespace std; typedef long long LL; typedef long double LD; typedef unsigned int uii; typedef pair<int, int> pii; typedef pair<int, pair<int, int>> piii; typedef unsigned long long uLL; typedef vector<int> vii; const int inf = 1e9; const LL INF = 1e18; const int M = 1e9 + 7; //__int128 const int maxn = 3e5; char s[maxn]; bool ok(int x, int y) { for (int i = x + 1; i <= y; ++i) { if (s[i - 1] == '#' && s[i] == '#') { return 0; } } return 1; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d, n; cin >> n >> a >> b >> c >> d >> (s + 1); if (s[c] == '#' || s[d] == '#' || !ok(b, d) || !ok(a, c)) { cout << "No" << endl; return 0; } if (c < d) { cout << "Yes" << endl; } else { for (int i = b; i <= d; ++i) { if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define pb push_back #define mk make_pair #define eps 1e-8 #define fi first #define se second #define all(x) (x).begin(), (x).end() using namespace std; typedef long long LL; typedef long double LD; typedef unsigned int uii; typedef pair<int, int> pii; typedef pair<int, pair<int, int>> piii; typedef unsigned long long uLL; typedef vector<int> vii; const int inf = 1e9; const LL INF = 1e18; const int M = 1e9 + 7; //__int128 const int maxn = 3e5; char s[maxn]; bool ok(int x, int y) { for (int i = x + 1; i <= y; ++i) { if (s[i - 1] == '#' && s[i] == '#') { return 0; } } return 1; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d, n; cin >> n >> a >> b >> c >> d >> (s + 1); if (s[c] == '#' || s[d] == '#' || !ok(b, d) || !ok(a, c)) { cout << "No" << endl; return 0; } if (c < d) { cout << "Yes" << endl; } else { for (int i = b; i <= d; ++i) { if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; } return 0; }
replace
42
43
42
43
-11
p03017
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 100006; int T, a, b, c, d, n; char s[N]; bool fl; int main() { scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s + 1); s[n + 1] = s[n + 2] = s[n + 3] = '#'; s[b] = '#', fl = 1; for (; (a < c || b < d) && fl;) { while (a < c && a < b - 1) { if (a + 2 < b && a + 2 <= c && s[a + 1] == '#' && s[a + 2] != '#') a += 2; else if (a + 1 < b && a + 1 <= c && s[a + 1] != '#') a++; else break; } if (c > d && a == b - 1 && a + 2 <= c && s[a + 2] != '#') a += 2, swap(a, b), swap(c, d); if (a == c && b == d) break; s[b] = '.'; if (b + 2 <= d && s[b + 1] == '#' && s[b + 2] != '#') b += 2, s[b] = '#'; else if (b + 1 <= d && s[b + 1] != '#') b++, s[b] = '#'; else fl = 0; } if (a != c || b != d) fl = 0; puts(fl ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; const int N = 200006; int T, a, b, c, d, n; char s[N]; bool fl; int main() { scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s + 1); s[n + 1] = s[n + 2] = s[n + 3] = '#'; s[b] = '#', fl = 1; for (; (a < c || b < d) && fl;) { while (a < c && a < b - 1) { if (a + 2 < b && a + 2 <= c && s[a + 1] == '#' && s[a + 2] != '#') a += 2; else if (a + 1 < b && a + 1 <= c && s[a + 1] != '#') a++; else break; } if (c > d && a == b - 1 && a + 2 <= c && s[a + 2] != '#') a += 2, swap(a, b), swap(c, d); if (a == c && b == d) break; s[b] = '.'; if (b + 2 <= d && s[b + 1] == '#' && s[b + 2] != '#') b += 2, s[b] = '#'; else if (b + 1 <= d && s[b + 1] != '#') b++, s[b] = '#'; else fl = 0; } if (a != c || b != d) fl = 0; puts(fl ? "Yes" : "No"); }
replace
2
3
2
3
0
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans = 0; for (int i = 0; i < s.length() - 1; i++) { if (s[i] != 'A') continue; int p = i + 1; while (p < s.length() - 1) { assert(p <= s.length() - 2); if (s[p] == 'B' && s[p + 1] == 'C') { ans++; p++; } else if (s[p] != 'A') break; p++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long ans = 0; vector<int> count(s.length()); int t = 0; for (int i = s.length() - 1; i >= 0; i--) { if (i == s.length() - 1) count[i] = 0; else if (s[i] == 'B' && s[i + 1] == 'C') t++; else if (s[i] == 'A' || (s[i] == 'C' && s[i - 1] == 'B' && i >= 2)) count[i] = t; else t = 0; } for (int i = 0; i < s.length(); i++) { if (s[i] == 'A') ans += count[i]; } cout << ans << endl; return 0; }
replace
5
19
5
21
TLE
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 5, mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int ans = 0, ls = s.size(), p = s.find("BC", 0); while (p != string::npos) { s.erase(p, 2); int t = p - 1; while (t >= 0 && s[t] == 'A') --t, ++ans; s.insert(t + 1, "BC"); p = s.find("BC", p + 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 5, mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int ls = s.size(), lm = 0; ll ans = 0; for (int i = 0; i < ls - 1; ++i) { if (s[i] == 'B' && s[i + 1] == 'C') { ans += i - lm; ++lm, ++lm, ++i; } else if (s[i] != 'A') lm = i + 1; } cout << ans << endl; return 0; }
replace
10
18
10
18
TLE
p03018
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cfenv> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> // #include <bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; long long MOD = 1000000000 + 7; // ;//1000000000 + 7 998244353 924844033 1000000000 + 9; constexpr long long INF = numeric_limits<LL>::max(); constexpr long long DINF = 1000000000000; const double PI = acos(-1); #define fir first #define sec second #define thi third #define debug(x) cerr << #x << ": " << x << '\n' typedef pair<LL, LL> Pll; typedef pair<double, double> Dll; typedef pair<LL, pair<LL, LL>> Ppll; typedef pair<LL, pair<LL, bitset<100001>>> Pbll; typedef pair<LL, pair<LL, vector<LL>>> Pvll; typedef pair<LL, LL> Vec2; struct Tll { LL first, second, third; }; struct Fll { LL first, second, third, fourth; }; typedef pair<LL, Tll> Ptll; #define rep(i, rept) for (LL i = 0; i < rept; i++) #define Rrep(i, mf) for (LL i = mf - 1; i >= 0; i--) void YN(bool f) { if (f) cout << "YES" << endl; else cout << "NO" << endl; } void yn(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; } struct Edge { LL to, cost; }; struct edge { LL from, to, cost; }; vector<vector<Edge>> g; vector<edge> ed; vector<Pll> pv; map<LL, LL> ma; set<LL> st; int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; LL n, m, k, p, q, w, h, ans, cnt, sum, a[3100], b[3100]; string str; bool f[1100]; char c; int main() { cin >> str; rep(i, str.size() - 2) { if (str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C') { cnt = i; while (cnt >= 0) { if (str[cnt] == 'A') ans++; else break; cnt--; if (cnt < 0) break; } str[i] = 'B', str[i + 1] = 'C', str[i + 2] = 'A'; } } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cfenv> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> // #include <bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; long long MOD = 1000000000 + 7; // ;//1000000000 + 7 998244353 924844033 1000000000 + 9; constexpr long long INF = numeric_limits<LL>::max(); constexpr long long DINF = 1000000000000; const double PI = acos(-1); #define fir first #define sec second #define thi third #define debug(x) cerr << #x << ": " << x << '\n' typedef pair<LL, LL> Pll; typedef pair<double, double> Dll; typedef pair<LL, pair<LL, LL>> Ppll; typedef pair<LL, pair<LL, bitset<100001>>> Pbll; typedef pair<LL, pair<LL, vector<LL>>> Pvll; typedef pair<LL, LL> Vec2; struct Tll { LL first, second, third; }; struct Fll { LL first, second, third, fourth; }; typedef pair<LL, Tll> Ptll; #define rep(i, rept) for (LL i = 0; i < rept; i++) #define Rrep(i, mf) for (LL i = mf - 1; i >= 0; i--) void YN(bool f) { if (f) cout << "YES" << endl; else cout << "NO" << endl; } void yn(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; } struct Edge { LL to, cost; }; struct edge { LL from, to, cost; }; vector<vector<Edge>> g; vector<edge> ed; vector<Pll> pv; map<LL, LL> ma; set<LL> st; int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; LL n, m, k, p, q, w, h, ans, cnt, sum, a[3100], b[3100]; string str; bool f[1100]; char c; int main() { cin >> str; rep(i, str.size() - 1) { if (str[i] == 'B' && str[i + 1] == 'C') { ans += cnt; i = i + 1; } else if (str[i] == 'A') cnt++; else cnt = 0; } cout << ans << endl; return 0; }
replace
93
107
93
101
0
p03018
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll h[200010], n, tt; char s[200010]; bool bo[200010]; inline int rd() { int x = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x; } int main() { scanf("%s", s + 1); n = strlen(s + 1); tt = 0; for (int i = 1; i <= n; i++) if (s[i] == 'A') { tt++; int id = 0; for (int j = i + 1; j <= n - 1; j += 2) if (s[j] == 'B' && s[j + 1] == 'C') h[tt]++; else { id = j; break; } if (id && s[id] == 'A') bo[tt] = true; } for (int i = tt - 1; i; i--) if (bo[i]) h[i] += h[i + 1]; ll ans = 0; for (int i = 1; i <= tt; i++) ans += h[i]; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll h[200010], n, tt; char s[200010]; bool bo[200010]; inline int rd() { int x = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x; } int main() { scanf("%s", s + 1); n = strlen(s + 1); tt = 0; for (int i = 1; i <= n; i++) if (s[i] == 'A') { tt++; int id = 0; for (int j = i + 1; j <= n - 1; j += 2) if (s[j] == 'B' && s[j + 1] == 'C') h[tt]++; else { id = j; break; } if (id && s[id] == 'A') bo[tt] = true; } for (int i = tt - 1; i > 0; i--) if (bo[i]) h[i] += h[i + 1]; ll ans = 0; for (int i = 1; i <= tt; i++) ans += h[i]; printf("%lld\n", ans); return 0; }
replace
36
37
36
37
0
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; int main() { string s; cin >> s; int cnt = 0, flag = 0, sz = s.size(); queue<int> que; for (int i = 0; i < sz - 2; i++) { if (s.substr(i, 3) == "ABC") que.push(i); } /*while(flag==0){ flag=1; for(int i=0; i<sz-2; i++){ if(s.substr(i,3)=="ABC"){ cnt++; flag=0; s[i]='B';s[i+1]='C';s[i+2]='A'; i++; } } }*/ while (!que.empty()) { int ind = que.front(); que.pop(); cnt++; s[ind] = 'B', s[ind + 1] = 'C', s[ind + 2] = 'A'; if (ind > 0) { if (s[ind - 1] == 'A') que.push(ind - 1); } if (ind + 4 < sz) { if (s.substr(ind + 3, 2) == "BC") que.push(ind + 2); } } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; int main() { string s; cin >> s; ll cnt = 0; int sz = s.size(); int numa1 = 0; // iまでに連なるaの数 int numa2 = 0; // iがbのとき前に連なるaの数 for (int i = 0; i < sz; i++) { // 最後がbのときcがきたらnuma2を足す if (s[i] == 'A') { numa1++; numa2 = 0; } else if (s[i] == 'B') { numa2 = numa1; numa1 = 0; } else { numa1 = numa2; cnt += numa2; numa2 = 0; if (i > 0 && s[i - 1] != 'B') numa1 = 0; } } cout << cnt; return 0; }
replace
8
38
8
26
TLE
p03018
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; long long a[100]; int main() { string s; cin >> s; int n = s.size(); int ans = 0, co = 0; for (int i = n - 2; i >= 0; i--) { if (s.substr(i, 2) == "BC") { for (int j = i - 1; j >= 0; j--) { if (j == 0) { if (s[j] == 'A') { co++; } ans += co; co = 0; break; } if (s[j] == 'A') { co++; } else { if (s.substr(j - 1, 2) == "BC") { j--; continue; } else { ans += co; co = 0; break; } } } } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; long long a[100]; int main() { string s; cin >> s; long long n = s.size(); long long ans = 0, co = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == 'A') { co++; } else if (s.substr(i, 2) == "BC") { ans += co; i++; continue; } else { co = 0; } } cout << ans << endl; }
replace
20
46
20
31
TLE
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int i = 0, ans = 0; while (i < (int)s.size() - 2) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; ans++; if (i > 0) i--; } else { i++; } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int A = 0, B = 0; ll ans = 0; REP(i, s.size()) { if (s[i] == 'A') { if (B == 0) A++; else { B = 0; A = 1; } } if (s[i] == 'B') { if (B == 0 && A > 0) B++; else if (B == 1) A = 0; } if (s[i] == 'C') { if (B == 0) A = 0; else { B = 0; ans += A; } } } cout << ans << '\n'; }
replace
12
23
12
36
TLE
p03018
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #pragma region using namespace std; #define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++) #define rep(i, n) FOR(i, 0LL, n) #define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--) #define rrep(i, n) RFOR(i, 0LL, n) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define COUNT(a, y, x) upper_bound(all(a), y) - lower_bound(all(a), x) #define UNIQUE(a) \ sort(all(a)); \ a.erase(unique(all(a)), a.end()) #define pb push_back typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<string> vs; typedef map<ll, ll> MAP; const ll inf = 1LL << 61; const ll mod = 1000000007LL; // const ll mod = 998244353LL; ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf; string s; bool ok; ll dx[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1}, dy[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1}; #define endl '\n' #pragma endregion #define MAX 222222 int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> s; ll len = s.size(); FOR(i, 0, len - 2) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { ans++; s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; if (i && s[i - 1] == 'A') { i -= 2; } } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #pragma region using namespace std; #define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++) #define rep(i, n) FOR(i, 0LL, n) #define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--) #define rrep(i, n) RFOR(i, 0LL, n) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define COUNT(a, y, x) upper_bound(all(a), y) - lower_bound(all(a), x) #define UNIQUE(a) \ sort(all(a)); \ a.erase(unique(all(a)), a.end()) #define pb push_back typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<string> vs; typedef map<ll, ll> MAP; const ll inf = 1LL << 61; const ll mod = 1000000007LL; // const ll mod = 998244353LL; ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf; string s; bool ok; ll dx[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1}, dy[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1}; #define endl '\n' #pragma endregion #define MAX 222222 int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> s; ll len = s.size(); ll cnt = 0; RFOR(i, 0, len) { if (s[i] == 'A') ans += cnt; else if (s[i] == 'B') { cnt = 0; } else { if (i && s[i - 1] == 'B') { cnt++; i--; } else { cnt = 0; } } } cout << ans << endl; return 0; }
replace
54
62
54
66
TLE
p03018
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'C') { s.replace(i, 2, 1, 'S'); } } int count = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'A' && s[i + 1] == 'S') { char tmp = s[i]; s[i] = s[i + 1]; s[i + 1] = tmp; i = -1; count++; } } cout << count << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'C') { s.replace(i, 2, 1, 'S'); } } long int count = 0; long int a_count = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'S') count += a_count; else if (s[i] == 'A') a_count++; else a_count = 0; } cout << count << endl; return 0; }
replace
17
26
17
26
TLE
p03018
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long arr[1000000]; int main() { string s; long long n, i, j, k, m, x, y, z; cin >> s; x = 0; y = 0; i = 0; while (i < s.length() - 1) { if (s[i] == 'A') { x++; i++; } else if (s[i] == 'B' && s[i + 1] == 'C') { if (x > 0) { y = x + y; x = 1; i = i + 2; } else { i = i + 2; } } else { x = 0; i++; } } i = s.length() - 1; while (i >= 0) { if (s[i] == 'A') { x++; i++; } else if (s[i] == 'B' && s[i + 1] == 'C') { if (x > 0) { y = x + y; x = x; i = i + 2; } else { i = i + 2; } } else { x = 0; i++; } } cout << y << endl; }
#include <bits/stdc++.h> using namespace std; long long arr[1000000]; int main() { string s; long long n, i, j, k, m, x, y, z; cin >> s; x = 0; y = 0; i = 0; while (i < s.length() - 1) { if (s[i] == 'A') { x++; i++; } else if (s[i] == 'B' && s[i + 1] == 'C') { if (x > 0) { y = x + y; x = x; i = i + 2; } else { i = i + 2; } } else { x = 0; i++; } } cout << y << endl; }
delete
11
29
11
11
-11
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, s, n) for (int i = (s); i <= (n); i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define REPR(i, s, n) for (int i = (s); i >= (n); i--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define Eunique(v) v.erase(unique(all(v)), v.end()) #define Eback(s) s.erase(s.end() - 1, s.end()) #define rev(v) reverse(all(v)) #define minvec(v) *min_element(all(v)) #define maxvec(v) *max_element(all(v)) #define sumvec(v) accumulate(all(v), 0LL) #define mapmin(v) v.rbegin()->first #define mapmax(v) v.begin()->first #define pb push_back #define pf push_front #define m_p make_pair #define DOUBLE fixed << setprecision(15) #define OK cerr << "OK\n" #define OK1 cerr << "OK1\n" #define OK2 cerr << "OK2\n" #define SIZE(s) (int)s.size() #define INF ((1LL << 62) - (1LL << 31)) #define zero(x, n) setw(x) << setfill('0') << n typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<long long> vll; typedef vector<vll> vvll; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; const double pi = acos(-1.0); const int mod = 1000000007; const int mod2 = 998244353; template <class A, class B> ostream &operator<<(ostream &ost, const pair<A, B> &p) { ost << "{" << p.first << ", " << p.second << "} "; return ost; } template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) { ost << "{"; for (int i = 0; i < (int)v.size(); i++) { if (i) ost << " "; ost << v[i]; } ost << "} \n"; return ost; } template <class A, class B> ostream &operator<<(ostream &ost, const map<A, B> &v) { ost << "{"; for (auto p : v) { ost << "{" << p.first << ", " << p.second << "} "; } ost << "} "; return ost; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void YES(bool b) { cout << ((b) ? "YES\n" : "NO\n"); } void Yes(bool b) { cout << ((b) ? "Yes\n" : "No\n"); } void yes(bool b) { cout << ((b) ? "yes\n" : "no\n"); } void Yay(bool b) { cout << ((b) ? "Yay!\n" : ":(\n"); } ll powmod(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } ll gcd(ll x, ll y) { return __gcd(x, y); } ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; } string replace_str(string &str, string from, string to) { const unsigned int pos = str.find(from); const int len = from.length(); if (pos == string::npos || from.empty()) return str; return str.replace(pos, len, to); } int main() { string s; cin >> s; while (s.find("BC") != string::npos) replace_str(s, "BC", "D"); ll n = (ll)s.size(); vs ss; string t = ""; rep(i, n) { if (s[i] == 'A' || s[i] == 'D') t += s[i]; else if (SIZE(t) != 0) { ss.pb(t); t = ""; } if (i == n - 1 && SIZE(t) != 0) ss.pb(t); } ll ans = 0; for (auto &&e : ss) { ll cnt = 0, sum = 0; rep(i, (ll)e.size()) { if (e[i] == 'D') { sum += i - cnt; cnt++; } } ans += sum; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, s, n) for (int i = (s); i <= (n); i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define REPR(i, s, n) for (int i = (s); i >= (n); i--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define Eunique(v) v.erase(unique(all(v)), v.end()) #define Eback(s) s.erase(s.end() - 1, s.end()) #define rev(v) reverse(all(v)) #define minvec(v) *min_element(all(v)) #define maxvec(v) *max_element(all(v)) #define sumvec(v) accumulate(all(v), 0LL) #define mapmin(v) v.rbegin()->first #define mapmax(v) v.begin()->first #define pb push_back #define pf push_front #define m_p make_pair #define DOUBLE fixed << setprecision(15) #define OK cerr << "OK\n" #define OK1 cerr << "OK1\n" #define OK2 cerr << "OK2\n" #define SIZE(s) (int)s.size() #define INF ((1LL << 62) - (1LL << 31)) #define zero(x, n) setw(x) << setfill('0') << n typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<long long> vll; typedef vector<vll> vvll; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; const double pi = acos(-1.0); const int mod = 1000000007; const int mod2 = 998244353; template <class A, class B> ostream &operator<<(ostream &ost, const pair<A, B> &p) { ost << "{" << p.first << ", " << p.second << "} "; return ost; } template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) { ost << "{"; for (int i = 0; i < (int)v.size(); i++) { if (i) ost << " "; ost << v[i]; } ost << "} \n"; return ost; } template <class A, class B> ostream &operator<<(ostream &ost, const map<A, B> &v) { ost << "{"; for (auto p : v) { ost << "{" << p.first << ", " << p.second << "} "; } ost << "} "; return ost; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void YES(bool b) { cout << ((b) ? "YES\n" : "NO\n"); } void Yes(bool b) { cout << ((b) ? "Yes\n" : "No\n"); } void yes(bool b) { cout << ((b) ? "yes\n" : "no\n"); } void Yay(bool b) { cout << ((b) ? "Yay!\n" : ":(\n"); } ll powmod(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } ll gcd(ll x, ll y) { return __gcd(x, y); } ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; } string replace_str(string &str, string from, string to) { const unsigned int pos = str.find(from); const int len = from.length(); if (pos == string::npos || from.empty()) return str; return str.replace(pos, len, to); } int main() { string tmp, s = ""; cin >> tmp; rep(i, SIZE(tmp) - 1) { if (tmp[i] == 'B' && tmp[i + 1] == 'C') { s += 'D'; i++; } else s += tmp[i]; } ll n = (ll)s.size(); vs ss; string t = ""; rep(i, n) { if (s[i] == 'A' || s[i] == 'D') t += s[i]; else if (SIZE(t) != 0) { ss.pb(t); t = ""; } if (i == n - 1 && SIZE(t) != 0) ss.pb(t); } ll ans = 0; for (auto &&e : ss) { ll cnt = 0, sum = 0; rep(i, (ll)e.size()) { if (e[i] == 'D') { sum += i - cnt; cnt++; } } ans += sum; } cout << ans << endl; return 0; }
replace
122
126
122
131
TLE
p03018
C++
Time Limit Exceeded
/* `-:://:::- `//:-------:/:` .+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .o:--...```..---+/` `/y+o/---....---:+o. `...````-os+/:---:/+o/--.` `-/+++++/:. `...` :h+d+oooo+/+-` ... `/++//:::://++-`....` -.`//````````:` `..` `o+/::------://o/` `-` -. -` `..` `---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..`` `....o+:-++/:--.```..-://s. `-` .- -` `-o: .-//::::/:-` `:s+/:--....-::/+s-` .- `- -` -///:--------:/:` ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ `+:--........--:/` .:ooo+++++osso-` `.:-...`/` ./::-------:/:` -` :+--..``````.--:+:...-+:-` `.-/+++++/+-.-` -. ``:so:/:--.......--:+` `-```````o+/+--..`````..--:o/-..:s+:. ```````:``.. `-` -` `+:--..`````..--/+-.../.`````..-o:--.......---/o. ` `: `:- -. .o:--..`` ``..--:o` `-` `:o+:--------:+o-` `-`-... .. .o/--...```..--:+/` `-` `oy/so/////++o/.` -/` `-` `- ``+s/o/:---...---:++. `-` .-../d://///:-.` `.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-. ```` `:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `- -++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `- `` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.- -----ss+:++/:--.```..-://s. /. `:: `-:. ./` `````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-` `-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-` `:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-` `./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:. ``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `- `.:--h.``..``` -.-`.- .- `+:--..`````..--//` `- /s-//::::::::. -` `/- .. .o:--..`` ``..--:o.```.- `//:--------://` -` .-`.-` -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+` ..`-. `-. ``:os:o/:---...---:++. `- ``///+:-..``````.--:+-````-.` `.:///////.-` .:-..` -``-+o+/:::::/+o/. `- `:+:-..`````..--:o/:--/ys+- `-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o. `.` `++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-` `````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.` -----syo/o+/:--.```..-://s. .-` `- .- `... ``-:////:-`` .` `/s//:--....-::/+s. -. `-` .- `..` .+o+/:::--:://+s/-..` .::+y ``` .- `..` ./oo++////+oso-` `.... :y-+:::::::/` ... `.:+oooooo/-` `....-. .//:-------:/:-.` ``...`` /+:+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .+/--...```..--:+/` `-o/:---...---:++. `-+o+/:---:/+o/. `.:+oooo+/-.` `````` */ #ifdef aimbot #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <limits> #include <list> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <string> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <vector> #define random escape__from__random__aetuhoetnuhshe #define mt make_tuple #define x first #define y second #define pb push_back #define ppb pop_back #define mp make_pair #define umap unordered_map #define uset unordered_set #define elif else if #define len(v) ((int)v.size()) #define f(i, n) for (int i = 0; i < (n); i++) #define rof(i, n) for (int i = ((n)-1); i >= 0; i--) #define apply(v, act) \ for (auto &x : v) { \ act; \ } #define log(args...) \ { \ string s = #args; \ deque<string> deq; \ string buf = ""; \ int bal = 0; \ for (char c : s) { \ if (c == '(' || c == '[' || c == '{') { \ bal++; \ } else if (c == ')' || c == ']' || c == '}') { \ bal--; \ } else { \ if (bal == 0) { \ if (c == ',') { \ deq.pb(buf); \ buf = ""; \ } else { \ if (c != ' ') { \ buf += c; \ } \ } \ } \ } \ } \ if (!buf.empty()) { \ deq.pb(buf); \ } \ smart_io::precall_print(); \ smart_io::_print(deq, args); \ } inline int min(const int &x, const int &y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } inline int max(const int &x, const int &y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } inline long long min(const long long &x, const long long &y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; } inline long long max(const long long &x, const long long &y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y; } #define print \ smart_io::precall_print(); \ cout, #define scan cin, #ifdef fast_allocator const int MAXMEM = 200 * 1000 * 1024; char _memory[MAXMEM]; size_t _ptr = 0; void *operator new(size_t _x) { _ptr += _x; assert(_ptr < MAXMEM); return _memory + _ptr - _x; } void operator delete(void *) noexcept {} #endif using namespace std; char string_in_buffer[(int)2e6]; void fast_scan(int &x) { scanf("%d", &x); } void fast_scan(long long &x) { scanf("%lld", &x); } void fast_scan(unsigned long long &x) { scanf("%llu", &x); } void fast_scan(double &x) { scanf("%lf", &x); } void fast_scan(long double &x) { scanf("%Lf", &x); } void fast_scan(char &x) { scanf("%c", &x); if (x == '\n') { fast_scan(x); } } void fast_scan(string &x) { scanf("%s", string_in_buffer); x = string(string_in_buffer); } template <class TFirst, class TSecond> void fast_scan(pair<TFirst, TSecond> &p) { fast_scan(p.first); fast_scan(p.second); } template <class T> void fast_scan(vector<T> &v) { for (auto &x : v) fast_scan(x); } void fast_print(const int &x) { printf("%d", x); } void fast_print(const unsigned int &x) { printf("%u", x); } void fast_print(const long long &x) { printf("%lld", x); } void fast_print(const unsigned long long &x) { printf("%llu", x); } void fast_print(const double &x) { printf("%.15lf", x); } void fast_print(const long double &x) { printf("%.15Lf", x); } void fast_print(const char &x) { printf("%c", x); }; void fast_print(const string &x) { printf("%s", x.c_str()); } void fast_print(const char v[]) { fast_print((string)v); } template <class TFirst, class TSecond> void fast_print(const pair<TFirst, TSecond> &p) { fast_print(p.first); fast_print(' '); fast_print(p.second); } template <class T> void fast_print(const vector<T> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print(' '); fast_print(v[i]); } } template <class T> void fast_print(const vector<vector<T>> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print('\n'); fast_print(v[i]); } } template <class T> void fast_print(const T &v) { for (const auto &x : v) { fast_print(x); fast_print(' '); } } using namespace std; namespace smart_io { string print_start = ""; string sep = " "; bool first_print = false; void precall_print() { fast_print(print_start); print_start = "\n"; first_print = true; } void _print(deque<string>) {} template <class T, class... Args> void _print(deque<string> names, T elem, Args... args) { if (!first_print) { fast_print("\n"); } else { first_print = false; } fast_print(names.front()); fast_print(" = "); fast_print(elem); names.pop_front(); _print(names, args...); } } // namespace smart_io template <class T> ostream &operator,(ostream &os, const T &object) { if (!smart_io::first_print) { fast_print(smart_io::sep); } else { smart_io::first_print = false; } fast_print(object); return os; } template <class T> istream &operator,(istream &is, T &object) { fast_scan(object); return is; } namespace random { using namespace std::chrono; mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch()) .count()); uniform_real_distribution<> prob_dist(0.0, 1.0); }; // namespace random namespace typedefs { typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef long double ld; } // namespace typedefs namespace numbers_operation { template <class T> T floor_mod(T a, T b) { if (a >= 0 && b >= 0) return a % b; if (a <= 0 && b <= 0) return a % b; return abs(b) - (abs(a) % abs(b)); } } // namespace numbers_operation using namespace numbers_operation; using namespace typedefs; using namespace random; int _st(string s) { int i = 0; int cnt = 0; while (i + 2 < len(s)) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; cnt++; i--; } else i++; i = max(i, 0); } return cnt; } signed main(signed argc, char *argv[]) { string s; scan s; print _st(s); }
/* `-:://:::- `//:-------:/:` .+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .o:--...```..---+/` `/y+o/---....---:+o. `...````-os+/:---:/+o/--.` `-/+++++/:. `...` :h+d+oooo+/+-` ... `/++//:::://++-`....` -.`//````````:` `..` `o+/::------://o/` `-` -. -` `..` `---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..`` `....o+:-++/:--.```..-://s. `-` .- -` `-o: .-//::::/:-` `:s+/:--....-::/+s-` .- `- -` -///:--------:/:` ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ `+:--........--:/` .:ooo+++++osso-` `.:-...`/` ./::-------:/:` -` :+--..``````.--:+:...-+:-` `.-/+++++/+-.-` -. ``:so:/:--.......--:+` `-```````o+/+--..`````..--:o/-..:s+:. ```````:``.. `-` -` `+:--..`````..--/+-.../.`````..-o:--.......---/o. ` `: `:- -. .o:--..`` ``..--:o` `-` `:o+:--------:+o-` `-`-... .. .o/--...```..--:+/` `-` `oy/so/////++o/.` -/` `-` `- ``+s/o/:---...---:++. `-` .-../d://///:-.` `.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-. ```` `:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `- -++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `- `` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.- -----ss+:++/:--.```..-://s. /. `:: `-:. ./` `````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-` `-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-` `:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-` `./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:. ``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `- `.:--h.``..``` -.-`.- .- `+:--..`````..--//` `- /s-//::::::::. -` `/- .. .o:--..`` ``..--:o.```.- `//:--------://` -` .-`.-` -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+` ..`-. `-. ``:os:o/:---...---:++. `- ``///+:-..``````.--:+-````-.` `.:///////.-` .:-..` -``-+o+/:::::/+o/. `- `:+:-..`````..--:o/:--/ys+- `-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o. `.` `++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-` `````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.` -----syo/o+/:--.```..-://s. .-` `- .- `... ``-:////:-`` .` `/s//:--....-::/+s. -. `-` .- `..` .+o+/:::--:://+s/-..` .::+y ``` .- `..` ./oo++////+oso-` `.... :y-+:::::::/` ... `.:+oooooo/-` `....-. .//:-------:/:-.` ``...`` /+:+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .+/--...```..--:+/` `-o/:---...---:++. `-+o+/:---:/+o/. `.:+oooo+/-.` `````` */ #ifdef aimbot #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <limits> #include <list> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <string> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <vector> #define random escape__from__random__aetuhoetnuhshe #define mt make_tuple #define x first #define y second #define pb push_back #define ppb pop_back #define mp make_pair #define umap unordered_map #define uset unordered_set #define elif else if #define len(v) ((int)v.size()) #define f(i, n) for (int i = 0; i < (n); i++) #define rof(i, n) for (int i = ((n)-1); i >= 0; i--) #define apply(v, act) \ for (auto &x : v) { \ act; \ } #define log(args...) \ { \ string s = #args; \ deque<string> deq; \ string buf = ""; \ int bal = 0; \ for (char c : s) { \ if (c == '(' || c == '[' || c == '{') { \ bal++; \ } else if (c == ')' || c == ']' || c == '}') { \ bal--; \ } else { \ if (bal == 0) { \ if (c == ',') { \ deq.pb(buf); \ buf = ""; \ } else { \ if (c != ' ') { \ buf += c; \ } \ } \ } \ } \ } \ if (!buf.empty()) { \ deq.pb(buf); \ } \ smart_io::precall_print(); \ smart_io::_print(deq, args); \ } inline int min(const int &x, const int &y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } inline int max(const int &x, const int &y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } inline long long min(const long long &x, const long long &y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; } inline long long max(const long long &x, const long long &y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y; } #define print \ smart_io::precall_print(); \ cout, #define scan cin, #ifdef fast_allocator const int MAXMEM = 200 * 1000 * 1024; char _memory[MAXMEM]; size_t _ptr = 0; void *operator new(size_t _x) { _ptr += _x; assert(_ptr < MAXMEM); return _memory + _ptr - _x; } void operator delete(void *) noexcept {} #endif using namespace std; char string_in_buffer[(int)2e6]; void fast_scan(int &x) { scanf("%d", &x); } void fast_scan(long long &x) { scanf("%lld", &x); } void fast_scan(unsigned long long &x) { scanf("%llu", &x); } void fast_scan(double &x) { scanf("%lf", &x); } void fast_scan(long double &x) { scanf("%Lf", &x); } void fast_scan(char &x) { scanf("%c", &x); if (x == '\n') { fast_scan(x); } } void fast_scan(string &x) { scanf("%s", string_in_buffer); x = string(string_in_buffer); } template <class TFirst, class TSecond> void fast_scan(pair<TFirst, TSecond> &p) { fast_scan(p.first); fast_scan(p.second); } template <class T> void fast_scan(vector<T> &v) { for (auto &x : v) fast_scan(x); } void fast_print(const int &x) { printf("%d", x); } void fast_print(const unsigned int &x) { printf("%u", x); } void fast_print(const long long &x) { printf("%lld", x); } void fast_print(const unsigned long long &x) { printf("%llu", x); } void fast_print(const double &x) { printf("%.15lf", x); } void fast_print(const long double &x) { printf("%.15Lf", x); } void fast_print(const char &x) { printf("%c", x); }; void fast_print(const string &x) { printf("%s", x.c_str()); } void fast_print(const char v[]) { fast_print((string)v); } template <class TFirst, class TSecond> void fast_print(const pair<TFirst, TSecond> &p) { fast_print(p.first); fast_print(' '); fast_print(p.second); } template <class T> void fast_print(const vector<T> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print(' '); fast_print(v[i]); } } template <class T> void fast_print(const vector<vector<T>> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print('\n'); fast_print(v[i]); } } template <class T> void fast_print(const T &v) { for (const auto &x : v) { fast_print(x); fast_print(' '); } } using namespace std; namespace smart_io { string print_start = ""; string sep = " "; bool first_print = false; void precall_print() { fast_print(print_start); print_start = "\n"; first_print = true; } void _print(deque<string>) {} template <class T, class... Args> void _print(deque<string> names, T elem, Args... args) { if (!first_print) { fast_print("\n"); } else { first_print = false; } fast_print(names.front()); fast_print(" = "); fast_print(elem); names.pop_front(); _print(names, args...); } } // namespace smart_io template <class T> ostream &operator,(ostream &os, const T &object) { if (!smart_io::first_print) { fast_print(smart_io::sep); } else { smart_io::first_print = false; } fast_print(object); return os; } template <class T> istream &operator,(istream &is, T &object) { fast_scan(object); return is; } namespace random { using namespace std::chrono; mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch()) .count()); uniform_real_distribution<> prob_dist(0.0, 1.0); }; // namespace random namespace typedefs { typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef long double ld; } // namespace typedefs namespace numbers_operation { template <class T> T floor_mod(T a, T b) { if (a >= 0 && b >= 0) return a % b; if (a <= 0 && b <= 0) return a % b; return abs(b) - (abs(a) % abs(b)); } } // namespace numbers_operation using namespace numbers_operation; using namespace typedefs; using namespace random; int _st(string s) { int i = 0; int cnt = 0; while (i + 2 < len(s)) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; cnt++; i--; } else i++; i = max(i, 0); } return cnt; } signed main(signed argc, char *argv[]) { string s; scan s; ll cnt = 0; int a = 0; for (int i = 0; i < len(s) - 1; i++) { if (s[i] == 'A') { a++; } else if (s[i] == 'B' && s[i + 1] == 'C') { cnt += a; i++; } else { a = 0; } } print cnt; }
replace
353
355
353
367
TLE
p03018
C++
Runtime Error
#include <bits/stdc++.h> #define reps(i, a, b) for (long long int i = a; i < b; i++) #define rep(i, a) for (long long int i = 0; i < a; i++) typedef long long int ll; using namespace std; ll MOD = 1000000007; const int MAX = 510000; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int main() { string S; cin >> S; vector<vector<int>> a(100000); ll ans = 0; int imabasho = 0; rep(i, S.size()) { if (S[i] == 'A') { a[imabasho].push_back(1); } else { if (S[i] == 'B' && S[i + 1] == 'C') { a[imabasho].push_back(2); i++; } else { if (S[i] == 'B') { imabasho++; } else { imabasho++; } } } } rep(i, imabasho + 1) { int count = 0; rep(j, a[i].size()) { if (a[i][j] == 2) { ans += ll(j) - count; count++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define reps(i, a, b) for (long long int i = a; i < b; i++) #define rep(i, a) for (long long int i = 0; i < a; i++) typedef long long int ll; using namespace std; ll MOD = 1000000007; const int MAX = 510000; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int main() { string S; cin >> S; vector<vector<int>> a(200000); ll ans = 0; int imabasho = 0; rep(i, S.size()) { if (S[i] == 'A') { a[imabasho].push_back(1); } else { if (S[i] == 'B' && S[i + 1] == 'C') { a[imabasho].push_back(2); i++; } else { if (S[i] == 'B') { imabasho++; } else { imabasho++; } } } } rep(i, imabasho + 1) { int count = 0; rep(j, a[i].size()) { if (a[i][j] == 2) { ans += ll(j) - count; count++; } } } cout << ans << endl; return 0; }
replace
20
21
20
21
0
p03018
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> #ifndef ONLINE_JUDGE // #define DEBUG #endif #ifdef DEBUG #define IFD(...) __VA_ARGS__ #define IFN(...) #define L cout << __LINE__ << "\n"; #define PRINT(...) __VA_ARGS__ cout << __LINE__ << " : " << #__VA_ARGS__ << "\n" #define PRT(x) cout << __LINE__ << " : " << #x << " = " << x << "\n" #else // DEBUG #define IFD(...) #define IFN(...) __VA_ARGS__ #define L #define PRINT(...) __VA_ARGS__ #define PRT(x) #endif // DEBUG #define it iterator #define rit reverse_iterator #define mp make_pair #define mems(a, b) memset(a, b, sizeof(a)) #define mem0(a) mems(a, 0) #define mem1(a) mems(a, 1) #define mem255(a) mems(a, 255) #define all(c) begin(c), end(c) #define sz(c) ((long long)((c).size())) #define phb push_back #define ppb pop_back #define phf push_front #define ppf pop_front #define fort0(i, a, b) for (ll i = a, i##_TO = b; i < i##_TO; i++) #define for0(i, n) fort0(i, 0, n) #define fort1(i, a, b) for (ll i = a, i##_TO = b; i <= i##_TO; i++) #define for1(i, n) fort1(i, 1, n) #define ford(i, a, b) for (ll i = a, i##_TO = b; i >= i##_TO; i--) #define loop(n) for0(LOOP_COUNTER, n) #define start_program IFD((start_time = clock())) #define runtime ((clock() - start_time) * 1.0 / CLOCKS_PER_SEC) #define halt(s) \ cout << s, IFD(cout << fixed << setprecision(10) << "\n\nTIME: " << runtime \ << " sec\n\n", ) exit(0) #define x first #define y second using namespace std; using namespace __gnu_pbds; // pb_ds using namespace __gnu_cxx; #define int ll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class key, class val = null_type, /// null_mapped_type class comp = less<key>> using ord_set = tree /// find_by_order(), order_of_key() <key, val, comp, rb_tree_tag, tree_order_statistics_node_update>; typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie; /// insert(), prefix_range() template <class T, class U> ostream &operator<<(ostream &out, pair<T, U> p) { #ifdef DEBUG return out << "(" << p.x << "," << p.y << ")"; #else return out << p.x << " " << p.y; #endif } template <class T, class U> istream &operator>>(istream &in, pair<T, U> p) { return in >> p.x >> p.y; } template <class Iter, class Str> struct _rng_ { Iter from, to; Str delim; _rng_(Iter from, Iter to, Str delim) : from(from), to(to), delim(delim) {} }; template <class Iter, class Str> _rng_<Iter, Str> rng(Iter from, Iter to, Str delim) { return _rng_<Iter, Str>(from, to, delim); } template <class Iter> auto rng(Iter from, Iter to) { return rng(from, to, " "); } template <class Cont, class Str> auto rng(Cont &c, Str delim) { return rng(all(c), delim); } template <class Cont> auto rng(Cont &c) { return rng(all(c)); } template <class Iter, class Str> ostream &operator<<(ostream &out, _rng_<Iter, Str> r) { #ifdef DEBUG out << distance(r.from, r.to) << ":" << r.delim; #endif for (Iter i = r.from; i != r.to; i++) out << *i << r.delim; return out; } template <class Iter, class Str> istream &operator>>(istream &in, _rng_<Iter, Str> r) { for (Iter i = r.from; i != r.to; i++) in >> *i; return in; } template <class T> T read() { T res; cin >> res; return res; } template <class T> vector<T> read(int n) { vector<T> res(n); cin >> rng(res); return res; } IFD(clock_t start_time;) // const int MOD=; ll ppow(ll x, ll y, ll mod) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; y >>= 1; x = x * x % mod; } return res; } // const int N=; // const int INF=; // int a[N]; signed main() { IFN(ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);) string s; cin >> s; int ans = 0; for (int i = 0; i <= sz(s); i++) { if (i < 0) i = 0; int j = 0; while (i + j < sz(s) && s[i + j] == 'A' + j % 3) j++; j /= 3; ans += j * (j + 1) / 2; for (int t = 0; t < 2 * j; t++) s[i + t] = 'B' + t % 2; for (int t = 2 * j; t < 3 * j; t++) s[i + t] = 'A'; if (j) i -= 2; } cout << ans; IFD(cout << fixed << setprecision(10) << "\n\nTIME: " << runtime << " sec\n\n";) }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> #ifndef ONLINE_JUDGE // #define DEBUG #endif #ifdef DEBUG #define IFD(...) __VA_ARGS__ #define IFN(...) #define L cout << __LINE__ << "\n"; #define PRINT(...) __VA_ARGS__ cout << __LINE__ << " : " << #__VA_ARGS__ << "\n" #define PRT(x) cout << __LINE__ << " : " << #x << " = " << x << "\n" #else // DEBUG #define IFD(...) #define IFN(...) __VA_ARGS__ #define L #define PRINT(...) __VA_ARGS__ #define PRT(x) #endif // DEBUG #define it iterator #define rit reverse_iterator #define mp make_pair #define mems(a, b) memset(a, b, sizeof(a)) #define mem0(a) mems(a, 0) #define mem1(a) mems(a, 1) #define mem255(a) mems(a, 255) #define all(c) begin(c), end(c) #define sz(c) ((long long)((c).size())) #define phb push_back #define ppb pop_back #define phf push_front #define ppf pop_front #define fort0(i, a, b) for (ll i = a, i##_TO = b; i < i##_TO; i++) #define for0(i, n) fort0(i, 0, n) #define fort1(i, a, b) for (ll i = a, i##_TO = b; i <= i##_TO; i++) #define for1(i, n) fort1(i, 1, n) #define ford(i, a, b) for (ll i = a, i##_TO = b; i >= i##_TO; i--) #define loop(n) for0(LOOP_COUNTER, n) #define start_program IFD((start_time = clock())) #define runtime ((clock() - start_time) * 1.0 / CLOCKS_PER_SEC) #define halt(s) \ cout << s, IFD(cout << fixed << setprecision(10) << "\n\nTIME: " << runtime \ << " sec\n\n", ) exit(0) #define x first #define y second using namespace std; using namespace __gnu_pbds; // pb_ds using namespace __gnu_cxx; #define int ll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class key, class val = null_type, /// null_mapped_type class comp = less<key>> using ord_set = tree /// find_by_order(), order_of_key() <key, val, comp, rb_tree_tag, tree_order_statistics_node_update>; typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie; /// insert(), prefix_range() template <class T, class U> ostream &operator<<(ostream &out, pair<T, U> p) { #ifdef DEBUG return out << "(" << p.x << "," << p.y << ")"; #else return out << p.x << " " << p.y; #endif } template <class T, class U> istream &operator>>(istream &in, pair<T, U> p) { return in >> p.x >> p.y; } template <class Iter, class Str> struct _rng_ { Iter from, to; Str delim; _rng_(Iter from, Iter to, Str delim) : from(from), to(to), delim(delim) {} }; template <class Iter, class Str> _rng_<Iter, Str> rng(Iter from, Iter to, Str delim) { return _rng_<Iter, Str>(from, to, delim); } template <class Iter> auto rng(Iter from, Iter to) { return rng(from, to, " "); } template <class Cont, class Str> auto rng(Cont &c, Str delim) { return rng(all(c), delim); } template <class Cont> auto rng(Cont &c) { return rng(all(c)); } template <class Iter, class Str> ostream &operator<<(ostream &out, _rng_<Iter, Str> r) { #ifdef DEBUG out << distance(r.from, r.to) << ":" << r.delim; #endif for (Iter i = r.from; i != r.to; i++) out << *i << r.delim; return out; } template <class Iter, class Str> istream &operator>>(istream &in, _rng_<Iter, Str> r) { for (Iter i = r.from; i != r.to; i++) in >> *i; return in; } template <class T> T read() { T res; cin >> res; return res; } template <class T> vector<T> read(int n) { vector<T> res(n); cin >> rng(res); return res; } IFD(clock_t start_time;) // const int MOD=; ll ppow(ll x, ll y, ll mod) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; y >>= 1; x = x * x % mod; } return res; } // const int N=; // const int INF=; // int a[N]; signed main() { IFN(ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);) string s; cin >> s; int ans = 0; int k = 0; for (int i = 0; i < sz(s); i++) if (s[i] == 'A') k++; else if (i + 1 < sz(s) && s[i] == 'B' && s[i + 1] == 'C') ans += k, i++; else k = 0; cout << ans; IFD(cout << fixed << setprecision(10) << "\n\nTIME: " << runtime << " sec\n\n";) }
replace
160
175
160
168
TLE
p03018
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define S second #define F first typedef long long ll; typedef long double ld; using namespace std; const int INF = 1e9; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; int n; int A[maxn]; string s; vector<int> v; int dp[maxn]; signed main() { cin >> s; n = s.size(); if (s[0] == 'A') A[0] = 1; for (int i = 1; i < s.size(); i++) { if (s[i] == 'C' && s[i - 1] == 'B') v.push_back(i); if (s[i] == 'A') A[i] = A[i - 1] + 1; } if (v.empty()) return cout << 0, 0; ll ans = 0; dp[0] = A[v[0] - 2]; ans += dp[0]; for (int i = 1; i < v.size(); i++) { dp[i] = A[v[i] - 2]; if (A[v[i] - 2] == v[i] - v[i - 1] - 2) dp[i] += dp[i - 1]; ans += dp[i]; } cout << ans; }
#include <bits/stdc++.h> #define int long long #define S second #define F first typedef long long ll; typedef long double ld; using namespace std; const int INF = 1e9; const int maxn = 2e5 + 10; const int mod = 1e9 + 7; int n; int A[maxn]; string s; vector<int> v; int dp[maxn]; signed main() { cin >> s; n = s.size(); if (s[0] == 'A') A[0] = 1; for (int i = 1; i < s.size(); i++) { if (s[i] == 'C' && s[i - 1] == 'B') v.push_back(i); if (s[i] == 'A') A[i] = A[i - 1] + 1; } if (v.empty()) return cout << 0, 0; ll ans = 0; dp[0] = A[v[0] - 2]; ans += dp[0]; for (int i = 1; i < v.size(); i++) { dp[i] = A[v[i] - 2]; if (A[v[i] - 2] == v[i] - v[i - 1] - 2) dp[i] += dp[i - 1]; ans += dp[i]; } cout << ans; }
replace
12
13
12
13
0
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define show(x) cout << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int main() { char s[200010]; scanf("%s", s); int n = 200000; int ans = 0; rep(i, n - 2) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { int j = i + 3; s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; while (s[j] == 'B' && s[j + 1] == 'C') { s[j - 1] = 'B'; s[j] = 'C'; s[j + 1] = 'A'; ans++; j += 2; } i = max(0, i - 2); ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define show(x) cout << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int main() { string s; cin >> s; int n = s.size(); string t = ""; rep(i, n) { if (i != n - 1 && s[i] == 'B' && s[i + 1] == 'C') { t += 'D'; i++; } else t += s[i]; } ll numA = 0; ll ans = 0; rep(i, (int)t.size()) { if (t[i] == 'A') numA++; else if (t[i] == 'D') ans += numA; else numA = 0; } cout << ans << endl; return 0; }
replace
39
59
39
60
TLE
p03018
C++
Runtime Error
#pragma GCC optimize("O3") #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pi; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); ++i) #define pb push_back #define sz size #define f first #define s second int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; ll a, t; a = t = 0; F0R(i, (int)s.size() - 1) { if (s[i] == 'A') a++; else if (s[i] == 'B' && s[i + 1] == 'C') { i++; t += a; } else a = 0; } cout << t; return 0; }
#pragma GCC optimize("O3") #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pi; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); ++i) #define pb push_back #define sz size #define f first #define s second int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; ll a, t; a = t = 0; F0R(i, (int)s.size() - 1) { if (s[i] == 'A') a++; else if (s[i] == 'B' && s[i + 1] == 'C') { i++; t += a; } else a = 0; } cout << t; return 0; }
replace
16
18
16
18
0
p03018
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:16777216") #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i) #define ITER(it, a) \ for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(A, value) memset(A, value, sizeof(A)) #define ALL(V) V.begin(), V.end() #define SZ(V) (int)V.size() #define PB push_back #define MP make_pair const double PI = acos(-1.0); typedef long long Int; typedef long long LL; typedef unsigned long long UINT; typedef vector<int> VI; typedef pair<int, int> PII; typedef pair<double, double> PDD; const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 500000; const int MAX2 = 20007; const int IT = 18; const int BASE = 1000000000; const int CNT = 300; const int MOD = 1000000007; int n; char S[MAX]; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%s", S); n = strlen(S); int res = 0; for (int i = 0; i + 2 < n; ++i) { if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') { S[i] = 'B'; S[i + 1] = 'C'; S[i + 2] = 'A'; i -= 2; i = max(i, -1); ++res; } } cout << res << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:16777216") #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i) #define ITER(it, a) \ for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(A, value) memset(A, value, sizeof(A)) #define ALL(V) V.begin(), V.end() #define SZ(V) (int)V.size() #define PB push_back #define MP make_pair const double PI = acos(-1.0); typedef long long Int; typedef long long LL; typedef unsigned long long UINT; typedef vector<int> VI; typedef pair<int, int> PII; typedef pair<double, double> PDD; const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 500000; const int MAX2 = 20007; const int IT = 18; const int BASE = 1000000000; const int CNT = 300; const int MOD = 1000000007; int n; char S[MAX]; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%s", S); n = strlen(S); Int res = 0, cnt = 0; for (int i = 0; i + 1 < n; ++i) { if (S[i] == 'B' && S[i + 1] == 'C') { res += cnt; ++i; } else if (S[i] == 'A') ++cnt; else cnt = 0; } cout << res << endl; return 0; }
replace
63
73
63
72
TLE
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { string s; cin >> s; int n = s.size(); int ans = 0; bool ck = true; while (ck) { ck = false; for (int i = 0; i < n - 2; i++) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { ans++; ck = true; s[i] = 'B'; s[i + 1] = 'C'; s[i + 2] = 'A'; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { string s; cin >> s; int n = s.size(); ll ans = 0; ll cnt = 0; for (int i = 0; i < n - 2; i++) { if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') { ans += cnt + 1; s[i + 2] = 'A'; i++; } else if (s[i] == 'A') { cnt++; } else { cnt = 0; } } cout << ans << endl; return 0; }
replace
10
22
10
21
TLE
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef double db; typedef vector<ll> vll; typedef pair<ll, ll> pll; #define pb push_back #define mp make_pair #define MAX 1000000 #define mod 1000000007 #define all(_) _.begin(), _.end() #define F first #define S second #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); ll n, i, ans = 0; string s; cin >> s; n = s.size(); char prev = 'Z'; i = 0; while (i < n) { if (s[i] == 'A') { ll j = i; while (j < n) { if (prev == 'A' && s[j] == 'C') break; if (prev == 'C' && s[j] == 'C') break; if ((prev == 'B' && s[j] == 'B') || (prev == 'B' && s[j] == 'A')) break; prev = s[j++]; } ll ca = 0; while (i < j) { if (s[i] == 'A') ca++; if (s[i] == 'C') ans += ca; i++; } } else i++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef double db; typedef vector<ll> vll; typedef pair<ll, ll> pll; #define pb push_back #define mp make_pair #define MAX 1000000 #define mod 1000000007 #define all(_) _.begin(), _.end() #define F first #define S second #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); ll n, i, ans = 0; string s; cin >> s; n = s.size(); char prev = 'Z'; i = 0; while (i < n) { if (s[i] == 'A') { ll j = i; while (j < n) { if (prev == 'A' && s[j] == 'C') break; if (prev == 'C' && s[j] == 'C') break; if ((prev == 'B' && s[j] == 'B') || (prev == 'B' && s[j] == 'A')) break; prev = s[j++]; } ll ca = 0; while (i < j) { if (s[i] == 'A') ca++; if (s[i] == 'C') ans += ca; i++; } } else i++; prev = 'Z'; } cout << ans << endl; return 0; }
insert
51
51
51
52
TLE
p03018
C++
Time Limit Exceeded
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces1148C #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ll x, ll y, ll a, ll b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (int k = 0; k < n; k++) { cout << a[k] << " "; } cerr << "\n"; } ll mod = 1000000007; int main() { char s[222222]; int n; scanf("%s%n", s, &n); ll ans = 0; ll flag = 0; for (int k = 0; k < n - 2; k++) { if (s[k] == 'A' && s[k + 1] == 'B' && s[k + 2] == 'C') { ans++; if (flag) { ans += flag; } else { ll cur = k - 1; while (cur >= 0 && s[cur] == 'A') { s[cur + 2] = 'A'; s[cur] = 'B'; s[cur + 1] = 'C'; cur--; ans++; flag++; } s[k + 2] = 'A'; } } else { flag = 0; } } cout << ans << endl; return 0; }
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces1148C #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ll x, ll y, ll a, ll b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (int k = 0; k < n; k++) { cout << a[k] << " "; } cerr << "\n"; } ll mod = 1000000007; int main() { char s[222222]; int n; scanf("%s%n", s, &n); ll ans = 0; ll flag = 0; for (int k = 0; k < n - 1; k++) { if (s[k] == 'A') { flag++; } else if (s[k] == 'B' && s[k + 1] == 'C') { ans += flag; k++; } else { flag = 0; } } cout << ans << endl; return 0; }
replace
37
54
37
43
TLE
p03018
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rt "\n" #define sp " " #define test(n) cout << "test" << n << endl; #define fixsp(n) fixed << setprecision(n) #define defsp(n) defaultfloat << setprecision(n) #define kyopro \ ios::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define iikae auto & #define vector3D(K, N, M, DP) \ vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M))); #define vector4D(K, N, M, O, DP) \ vector<vector<vector<vector<ll>>>> DP( \ K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O)))); #define zenbu(a) a.begin(), a.end() #define rzenbu(a) a.rbegin(), a.rend() #define rep(i, s, N) for (ll i{s}; i < N; i++) #define rem(i, N, s) for (ll i{N}; i > s; i--) using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template <typename T> struct UnionFind { vector<T> par; UnionFind(T n) : par(n, -1) {} void init(T n) { par.assign(n, -1); } T root(T x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(T x, T y) { return root(x) == root(y); } bool merge(T x, T y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; template <typename T> ll combpm(T N_, T C_) { const int NUM_ = 400001; static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1]; if (fact[0] == 0) { inv[1] = fact[0] = factr[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i % MOD, factr[i] = factr[i - 1] * inv[i] % MOD; } if (C_ < 0 || C_ > N_) return 0; return factr[C_] * fact[N_] % MOD * factr[N_ - C_] % MOD; } /* ここからコード開始 */ int main() { kyopro; string s; cin >> s; ll exist{1}, sum{}; while (exist) { exist = 0; rep(i, 0, max((ll)s.size(), 0LL) - 2) { if (s.substr(i, 3) == "ABC") { s.replace(i, 3, "BCA"); exist = 1; sum++; } } } cout << sum << rt; }
#include <bits/stdc++.h> #define rt "\n" #define sp " " #define test(n) cout << "test" << n << endl; #define fixsp(n) fixed << setprecision(n) #define defsp(n) defaultfloat << setprecision(n) #define kyopro \ ios::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define iikae auto & #define vector3D(K, N, M, DP) \ vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M))); #define vector4D(K, N, M, O, DP) \ vector<vector<vector<vector<ll>>>> DP( \ K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O)))); #define zenbu(a) a.begin(), a.end() #define rzenbu(a) a.rbegin(), a.rend() #define rep(i, s, N) for (ll i{s}; i < N; i++) #define rem(i, N, s) for (ll i{N}; i > s; i--) using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template <typename T> struct UnionFind { vector<T> par; UnionFind(T n) : par(n, -1) {} void init(T n) { par.assign(n, -1); } T root(T x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(T x, T y) { return root(x) == root(y); } bool merge(T x, T y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; template <typename T> ll combpm(T N_, T C_) { const int NUM_ = 400001; static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1]; if (fact[0] == 0) { inv[1] = fact[0] = factr[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i % MOD, factr[i] = factr[i - 1] * inv[i] % MOD; } if (C_ < 0 || C_ > N_) return 0; return factr[C_] * fact[N_] % MOD * factr[N_ - C_] % MOD; } /* ここからコード開始 */ int main() { kyopro; string s; cin >> s; rep(i, 0, (ll)s.size() - 1) { if (s.substr(i, 2) == "BC") { s.replace(i, 2, "X"); } } ll sum{}, bA{}; rep(i, 0, (ll)s.size()) { if (s[i] == 'A') { bA++; } else if (s[i] == 'X') { sum += bA; } else { bA = 0; } } cout << sum << rt; }
replace
70
79
70
83
TLE