problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k โ | fixed_code stringlengths 12 526k โ | labels listlengths 0 15 โ | buggy_submission_id int64 1 1.54M โ | fixed_submission_id int64 2 1.54M โ | user_id stringlengths 10 10 โ | language stringclasses 9 values |
|---|---|---|---|---|---|---|---|
p03014 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int h, w, cnt = 0, ind = 0, max = 0;
cin >> h >> w;
string s[h];
vector<int> row_light[2000], col_light[2000];
for (int i = 0; i < 2000; i++) {
for (int j = 0; j < 2000; j++) {
row_light[i].push_back(0);
col_light[i].push_back(0);
}
}
for (int i = 0; i < h; i++) {
cin >> s[i];
cnt = 0;
ind = 0;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
fill(row_light[i].begin() + ind, row_light[i].begin() + j, cnt);
row_light[i][j] = 0;
cnt = 0;
ind = j + 1;
} else {
cnt++;
}
}
if (s[i][w - 1] == '.') {
fill(row_light[i].begin() + ind, row_light[i].begin() + w, cnt);
}
}
for (int i = 0; i < w; i++) {
cnt = 0;
ind = 0;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
fill(col_light[i].begin() + ind, col_light[i].begin() + j, cnt);
col_light[i][j] = 0;
cnt = 0;
ind = j + 1;
} else {
cnt++;
}
}
if (s[h - 1][i] == '.') {
fill(col_light[i].begin() + ind, col_light[i].begin() + w, cnt);
}
}
int num;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
num = row_light[i][j] + col_light[j][i] - 1;
max = (num < max) ? max : num;
}
}
cout << max << endl;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int h, w, cnt = 0, ind = 0, max = 0;
cin >> h >> w;
string s[h];
vector<int> row_light[2001], col_light[2001];
for (int i = 0; i < 2001; i++) {
for (int j = 0; j < 2001; j++) {
row_light[i].push_back(0);
col_light[i].push_back(0);
}
}
for (int i = 0; i < h; i++) {
cin >> s[i];
cnt = 0;
ind = 0;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
fill(row_light[i].begin() + ind, row_light[i].begin() + j, cnt);
row_light[i][j] = 0;
cnt = 0;
ind = j + 1;
} else {
cnt++;
}
}
if (s[i][w - 1] == '.') {
fill(row_light[i].begin() + ind, row_light[i].begin() + w, cnt);
}
}
for (int i = 0; i < w; i++) {
cnt = 0;
ind = 0;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
fill(col_light[i].begin() + ind, col_light[i].begin() + j, cnt);
col_light[i][j] = 0;
cnt = 0;
ind = j + 1;
} else {
cnt++;
}
}
if (s[h - 1][i] == '.') {
fill(col_light[i].begin() + ind, col_light[i].begin() + h, cnt);
}
}
int num;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
num = row_light[i][j] + col_light[j][i] - 1;
max = (num < max) ? max : num;
}
}
cout << max << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"identifier.change",
"call.arguments.change"
] | 828,164 | 828,165 | u352248517 | cpp |
p03014 | #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;
string S[H];
rep(i, H) { cin >> S[i]; }
int T[H][W];
int Y[H][W];
rep(i, H) rep(j, W) {
T[i][j] = -1;
Y[i][j] = -1;
}
rep(i, H) rep(j, W) {
if (S[i][j] == '.') {
if (T[i][j] == -1) {
int d = 0;
while (i + d < H and S[i + d][j] == '.') {
d++;
}
rep(k, d) T[i + k][j] = d;
}
if (Y[i][j] == -1) {
int d = 0;
while (i + d < W and S[i][j + d] == '.') {
d++;
}
rep(k, d) Y[i][j + k] = d;
}
}
}
int ans = 0;
rep(i, H) rep(j, W) {
if (S[i][j] == '.') {
ans = max(ans, max(0, T[i][j] - 1) + max(0, Y[i][j] - 1) + 1);
}
}
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;
string S[H];
rep(i, H) { cin >> S[i]; }
int T[H][W];
int Y[H][W];
rep(i, H) rep(j, W) {
T[i][j] = -1;
Y[i][j] = -1;
}
rep(i, H) rep(j, W) {
if (S[i][j] == '.') {
if (T[i][j] == -1) {
int d = 0;
while (i + d < H and S[i + d][j] == '.') {
d++;
}
rep(k, d) T[i + k][j] = d;
}
if (Y[i][j] == -1) {
int d = 0;
while (j + d < W and S[i][j + d] == '.') {
d++;
}
rep(k, d) Y[i][j + k] = d;
}
}
}
int ans = 0;
rep(i, H) rep(j, W) {
if (S[i][j] == '.') {
ans = max(ans, max(0, T[i][j] - 1) + max(0, Y[i][j] - 1) + 1);
}
}
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.condition.change"
] | 828,170 | 828,171 | u944316525 | cpp |
p03014 | #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[i];
}
vector<vector<int>> hor(h, vector<int>(w));
for (int i = 0; i < h; i++) {
vector<int> rock;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
rock.push_back(j);
}
}
rock.push_back(w);
int cur = 0;
for (int j = 0; j < w; j++) {
if (j == rock[cur])
cur++;
else {
int prev = 0;
if (cur)
prev = rock[cur - 1] + 1;
hor[i][j] = rock[cur] - prev;
}
}
}
int ret = 0;
for (int j = 0; j < w; j++) {
vector<int> rock;
for (int i = 0; i < h; i++) {
if (s[i][j] == '#') {
rock.push_back(i);
}
}
rock.push_back(h);
int cur = 0;
for (int i = 0; i < h; i++) {
if (j == rock[cur])
cur++;
else {
int prev = 0;
if (cur)
prev = rock[cur - 1] + 1;
ret = max(ret, hor[i][j] + rock[cur] - prev - 1);
}
}
}
cout << ret << 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[i];
}
vector<vector<int>> hor(h, vector<int>(w));
for (int i = 0; i < h; i++) {
vector<int> rock;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
rock.push_back(j);
}
}
rock.push_back(w);
int cur = 0;
for (int j = 0; j < w; j++) {
if (j == rock[cur])
cur++;
else {
int prev = 0;
if (cur)
prev = rock[cur - 1] + 1;
hor[i][j] = rock[cur] - prev;
}
}
}
int ret = 0;
for (int j = 0; j < w; j++) {
vector<int> rock;
for (int i = 0; i < h; i++) {
if (s[i][j] == '#') {
rock.push_back(i);
}
}
rock.push_back(h);
int cur = 0;
for (int i = 0; i < h; i++) {
if (i == rock[cur])
cur++;
else {
int prev = 0;
if (cur)
prev = rock[cur - 1] + 1;
ret = max(ret, hor[i][j] + rock[cur] - prev - 1);
}
}
}
cout << ret << endl;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 828,176 | 828,177 | u158758819 | cpp |
p03014 | #include <algorithm>
#include <cstdio>
using namespace std;
const int N = 2e3 + 10;
char s[N][N];
int l[N][N], r[N][N], u[N][N], d[N][N];
int n, m;
int main() {
int i, j, res = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++)
scanf(" %s ", s[i] + 1);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1, u[i][j] = u[i - 1][j] + 1;
else
l[i][j] = u[i][j] = 0;
for (i = n; i >= 1; i--)
for (j = m; j >= 1; j--)
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1, d[i][j] = d[i + 1][j] + 1;
else
r[i][j] = d[i][j] = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (s[i][j] == '.')
res = max(res, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
printf("%d\n", res);
return 0;
} | #include <algorithm>
#include <cstdio>
using namespace std;
const int N = 2e3 + 10;
char s[N][N];
int l[N][N], r[N][N], u[N][N], d[N][N];
int n, m;
int main() {
int i, j, res = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++)
scanf(" %s ", s[i] + 1);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1, u[i][j] = u[i - 1][j] + 1;
else
l[i][j] = u[i][j] = 0;
for (i = n; i >= 1; i--)
for (j = m; j >= 1; j--)
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1, d[i][j] = d[i + 1][j] + 1;
else
r[i][j] = d[i][j] = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
if (s[i][j] == '.')
res = max(res, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
printf("%d\n", res);
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,178 | 828,179 | u052620579 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long
typedef vector<int> vi;
typedef pair<int, int> pi;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) \
cout << #a << ": "; \
for (const auto &v : (a)) \
cout << v << endl
int H, W;
string S[2005];
int row[2005][2005];
int col[2005][2005];
signed main() {
cin >> H >> W;
REP(i, H) cin >> S[i];
REP(i, H) {
int pos = 0;
int cnt = 0;
REP(j, W) {
if (S[i][j] == '.') {
cnt++;
if (j == W - 1) {
REP2(k, pos, j) row[i][k] = cnt;
}
} else {
REP2(k, pos, j - 1) row[i][k] = cnt;
row[i][j] = 0;
pos = j + 1;
cnt = 0;
}
}
}
REP(j, W) {
int pos = 0;
int cnt = 0;
REP(i, H) {
if (S[i][j] == '.') {
cnt++;
if (i == H - 1) {
REP2(k, pos, i) col[k][j] = cnt;
}
} else {
REP2(k, pos, i - 1) col[k][j] = cnt;
col[i][j] = 0;
pos = i + 1;
cnt = 0;
}
}
}
int ans = 0;
REP(i, W) {
REP(j, H) { ans = max(ans, col[i][j] + row[i][j] - 1); }
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long
typedef vector<int> vi;
typedef pair<int, int> pi;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) \
cout << #a << ": "; \
for (const auto &v : (a)) \
cout << v << endl
int H, W;
string S[2005];
int row[2005][2005];
int col[2005][2005];
signed main() {
cin >> H >> W;
REP(i, H) cin >> S[i];
REP(i, H) {
int pos = 0;
int cnt = 0;
REP(j, W) {
if (S[i][j] == '.') {
cnt++;
if (j == W - 1) {
REP2(k, pos, j) row[i][k] = cnt;
}
} else {
REP2(k, pos, j - 1) row[i][k] = cnt;
row[i][j] = 0;
pos = j + 1;
cnt = 0;
}
}
}
REP(j, W) {
int pos = 0;
int cnt = 0;
REP(i, H) {
if (S[i][j] == '.') {
cnt++;
if (i == H - 1) {
REP2(k, pos, i) col[k][j] = cnt;
}
} else {
REP2(k, pos, i - 1) col[k][j] = cnt;
col[i][j] = 0;
pos = i + 1;
cnt = 0;
}
}
}
int ans = 0;
REP(i, H) {
REP(j, W) { ans = max(ans, col[i][j] + row[i][j] - 1); }
}
cout << ans << endl;
return 0;
}
| [] | 828,180 | 828,181 | u703272444 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MX LLONG_MAX
#define MN LLONG_MIN
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
ll powermodm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll power(ll _a, ll _b) {
ll _r = 1;
while (_b) {
if (_b % 2 == 1)
_r = (_r * _a);
_b /= 2;
_a = (_a * _a);
}
return _r;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (max(a, b) / gcd(a, b)) * min(a, b); }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m;
cin >> n >> m;
string s[n];
for (ll i = 0; i < n; i++) {
cin >> s[i];
// cout<<s[i]<<" "<<endl;
}
vector<ll> a[n + 1], b[m + 1];
for (ll i = 0; i < n; i++) {
a[i + 1].pb(0);
a[i + 1].pb(m + 1);
}
for (ll i = 0; i < m; i++) {
b[i + 1].pb(0);
b[i + 1].pb(n + 1);
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i][j] == '#') {
// cout<<i+1<<" "<<j+1<<endl;
a[i + 1].pb(j + 1);
b[j + 1].pb(i + 1);
}
}
}
for (ll i = 1; i <= n; i++)
sort(a[i].begin(), a[i].end());
for (ll j = 1; j <= m; j++)
sort(b[j].begin(), b[j].end());
// for(ll i=0;i<n;i++)
// {
// for(ll j=0;j<a[i+1].size();j++)
// cout<<a[i+1][j]<<" ";
// cout<<endl;
// }
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i][j] == '.') {
// cout<<i+1<<" "<<j+1<<endl;
ll x = i + 1;
ll y = j + 1;
ll l = 0, r = a[x].size() - 1;
ll left = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (a[x][mid] < y) {
l = mid + 1;
left = max(left, a[x][mid]);
} else {
r = mid - 1;
}
}
l = 0;
r = a[x].size() - 1;
ll right = m + 1;
while (l <= r) {
ll mid = (l + r) >> 1;
if (a[x][mid] > y) {
r = mid - 1;
right = min(right, a[x][mid]);
} else {
l = mid + 1;
}
}
l = 0;
r = b[y].size() - 1;
ll up = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (b[y][mid] < x) {
l = mid + 1;
up = max(up, b[y][mid]);
} else {
r = mid - 1;
}
}
l = 0;
r = b[y].size() - 1;
ll down = n + 1;
while (l <= r) {
ll mid = (l + r) >> 1;
if (b[y][mid] > y) {
r = mid - 1;
down = min(down, b[y][mid]);
} else {
l = mid + 1;
}
}
// cout<<left<<" "<<right<<" "<<up<<" "<<down<<endl;
// cout<<y-left<<" "<<right-y<<" "<<x-up<<" "<<down-x<<endl;
ll tmp = (y - left) + (right - y) + (x - up) + (down - x) - 3;
// cout<<tmp<<endl;
ans = max(ans, (y - left) + (right - y) + (x - up) + (down - x) - 3);
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MX LLONG_MAX
#define MN LLONG_MIN
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
ll powermodm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll power(ll _a, ll _b) {
ll _r = 1;
while (_b) {
if (_b % 2 == 1)
_r = (_r * _a);
_b /= 2;
_a = (_a * _a);
}
return _r;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (max(a, b) / gcd(a, b)) * min(a, b); }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m;
cin >> n >> m;
string s[n];
for (ll i = 0; i < n; i++) {
cin >> s[i];
// cout<<s[i]<<" "<<endl;
}
vector<ll> a[n + 1], b[m + 1];
for (ll i = 0; i < n; i++) {
a[i + 1].pb(0);
a[i + 1].pb(m + 1);
}
for (ll i = 0; i < m; i++) {
b[i + 1].pb(0);
b[i + 1].pb(n + 1);
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i][j] == '#') {
// cout<<i+1<<" "<<j+1<<endl;
a[i + 1].pb(j + 1);
b[j + 1].pb(i + 1);
}
}
}
for (ll i = 1; i <= n; i++)
sort(a[i].begin(), a[i].end());
for (ll j = 1; j <= m; j++)
sort(b[j].begin(), b[j].end());
// for(ll i=0;i<n;i++)
// {
// for(ll j=0;j<a[i+1].size();j++)
// cout<<a[i+1][j]<<" ";
// cout<<endl;
// }
// for(ll i=0;i<m;i++)
// {
// for(ll j=0;j<b[i+1].size();j++)
// cout<<b[i+1][j]<<" ";
// cout<<endl;
// }
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i][j] == '.') {
// cout<<i+1<<" "<<j+1<<endl;
ll x = i + 1;
ll y = j + 1;
ll l = 0, r = a[x].size() - 1;
ll left = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (a[x][mid] < y) {
l = mid + 1;
left = max(left, a[x][mid]);
} else {
r = mid - 1;
}
}
l = 0;
r = a[x].size() - 1;
ll right = m + 1;
while (l <= r) {
ll mid = (l + r) >> 1;
if (a[x][mid] > y) {
r = mid - 1;
right = min(right, a[x][mid]);
} else {
l = mid + 1;
}
}
l = 0;
r = b[y].size() - 1;
ll up = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (b[y][mid] < x) {
l = mid + 1;
up = max(up, b[y][mid]);
} else {
r = mid - 1;
}
}
l = 0;
r = b[y].size() - 1;
ll down = n + 1;
while (l <= r) {
ll mid = (l + r) >> 1;
if (b[y][mid] > x) {
r = mid - 1;
down = min(down, b[y][mid]);
} else {
l = mid + 1;
}
}
// cout<<left<<" "<<right<<" "<<up<<" "<<down<<endl;
// cout<<y-left<<" "<<right-y<<" "<<x-up<<" "<<down-x<<endl;
ll tmp = (y - left) + (right - y) + (x - up) + (down - x) - 3;
// cout<<tmp<<endl;
ans = max(ans, (y - left) + (right - y) + (x - up) + (down - x) - 3);
}
}
}
cout << ans;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 828,188 | 828,189 | u015252678 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<vector<int>> l(n, vector<int>(m));
vector<vector<int>> r(n, vector<int>(m));
vector<vector<int>> u(n, vector<int>(m));
vector<vector<int>> d(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j == 0) {
if (s[i][j] == '.')
l[i][j] = 1;
else
l[i][j] = 0;
} else {
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1;
else
l[i][j] = 0;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
if (j == m - 1) {
if (s[i][j] == '.')
r[i][j] = 1;
else
r[i][j] = 0;
} else {
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1;
else
r[i][j] = 0;
}
}
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (i == 0) {
if (s[i][j] == '.')
u[i][j] = 1;
else
u[i][j] = 0;
} else {
if (s[i][j] == '.')
u[i][j] = u[i - 1][j] + 1;
else
u[i][j] = 0;
}
}
}
for (int j = 0; j < n; j++) {
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1) {
if (s[i][j] == '.')
d[i][j] = 1;
else
d[i][j] = 0;
} else {
if (s[i][j] == '.')
d[i][j] = d[i + 1][j] + 1;
else
d[i][j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '.') {
ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<vector<int>> l(n, vector<int>(m));
vector<vector<int>> r(n, vector<int>(m));
vector<vector<int>> u(n, vector<int>(m));
vector<vector<int>> d(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j == 0) {
if (s[i][j] == '.')
l[i][j] = 1;
else
l[i][j] = 0;
} else {
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1;
else
l[i][j] = 0;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
if (j == m - 1) {
if (s[i][j] == '.')
r[i][j] = 1;
else
r[i][j] = 0;
} else {
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1;
else
r[i][j] = 0;
}
}
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (i == 0) {
if (s[i][j] == '.')
u[i][j] = 1;
else
u[i][j] = 0;
} else {
if (s[i][j] == '.')
u[i][j] = u[i - 1][j] + 1;
else
u[i][j] = 0;
}
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1) {
if (s[i][j] == '.')
d[i][j] = 1;
else
d[i][j] = 0;
} else {
if (s[i][j] == '.')
d[i][j] = d[i + 1][j] + 1;
else
d[i][j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '.') {
ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
}
}
}
cout << ans;
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,192 | 828,193 | u387147192 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x) \
int n; \
while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define fin << '\n'
#define __ << " " <<
#define ___ << " "
#define bash push_back
#define ALL(x) x.begin(), x.end()
#define SWAP(a, b) ((a != b) && (a += b, b = a - b, a -= b))
//#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef vector<pii> vpi;
typedef greater<pii> gpi;
typedef priority_queue<pii, vpi, gpi> dijk;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
static const signed int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
bool inside(int x, int y, int w, int h) {
return (x >= 0 && y >= 0 && x < w && y < h);
}
template <class T> T abs(T &x) { return x < 0 ? -x : x; }
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;
}
int qp(int a, ll b, int mo) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
string s[2005];
int mas[2005][2005];
inline void solve() {
int h, w;
cin >> h >> w;
FOR(i, h) { cin >> s[i]; }
FOR(i, h) {
int sum = 0;
FOR(j, w) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] = sum;
}
sum = 0;
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
}
FOR(j, w) {
int sum = 0;
FOR(i, h) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
sum = 0;
for (int i = h - 1; i >= 0; i--) {
if (s[i][j] = '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
}
int maxi = -1;
FOR(i, h) {
FOR(j, w) { chmax(maxi, mas[i][j]); }
}
cout << maxi fin;
}
struct xyz {
xyz() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
};
} xyzzy;
signed main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define why(n, x) \
int n; \
while (cin >> n, n != x)
#define iFOR(i, x, n) for (int i = x; i < n; i++)
#define fin << '\n'
#define __ << " " <<
#define ___ << " "
#define bash push_back
#define ALL(x) x.begin(), x.end()
#define SWAP(a, b) ((a != b) && (a += b, b = a - b, a -= b))
//#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vit;
typedef map<string, int> mstit;
typedef vector<pii> vpi;
typedef greater<pii> gpi;
typedef priority_queue<pii, vpi, gpi> dijk;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
static const signed int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
bool inside(int x, int y, int w, int h) {
return (x >= 0 && y >= 0 && x < w && y < h);
}
template <class T> T abs(T &x) { return x < 0 ? -x : x; }
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;
}
int qp(int a, ll b, int mo) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
string s[2005];
int mas[2005][2005];
inline void solve() {
int h, w;
cin >> h >> w;
FOR(i, h) { cin >> s[i]; }
FOR(i, h) {
int sum = 0;
FOR(j, w) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] = sum;
}
sum = 0;
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
}
FOR(j, w) {
int sum = 0;
FOR(i, h) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
sum = 0;
for (int i = h - 1; i >= 0; i--) {
if (s[i][j] == '.')
sum++;
else
sum = 0;
mas[i][j] += sum - 1;
}
}
int maxi = -1;
FOR(y, h) {
FOR(x, w) { chmax(maxi, mas[y][x]); }
}
cout << maxi fin;
}
struct xyz {
xyz() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
};
} xyzzy;
signed main() {
solve();
return 0;
}
| [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 828,196 | 828,197 | u678146855 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<string> board;
REP(i, H) {
string row;
cin >> row;
board.emplace_back(row);
}
vector<vector<int>> ans(H, vector<int>(W, 1));
REP(r, H) {
int now = 0, now_rev = 0;
REP(c, W) {
if (board[r][c] == '#') {
now = 0;
} else {
ans[r][c] += now;
now++;
}
if (board[r][W - c - 1] == '#') {
now_rev = 0;
} else {
ans[r][W - c - 1] += now_rev;
now_rev++;
}
}
}
REP(c, W) {
int now = 0, now_rev = 0;
REP(r, H) {
if (board[r][c] == '#') {
now = 0;
} else {
ans[r][c] += now;
now++;
}
if (board[H - r - 1][c] == '#') {
now = 0;
} else {
ans[H - r - 1][c] += now_rev;
now_rev++;
}
}
}
int ans_val = 0;
REP(i, H) REP(j, W) ans_val = max(ans_val, ans[i][j]);
cout << ans_val << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<string> board;
REP(i, H) {
string row;
cin >> row;
board.emplace_back(row);
}
vector<vector<int>> ans(H, vector<int>(W, 1));
REP(r, H) {
int now = 0, now_rev = 0;
REP(c, W) {
if (board[r][c] == '#') {
now = 0;
} else {
ans[r][c] += now;
now++;
}
if (board[r][W - c - 1] == '#') {
now_rev = 0;
} else {
ans[r][W - c - 1] += now_rev;
now_rev++;
}
}
}
REP(c, W) {
int now = 0, now_rev = 0;
REP(r, H) {
if (board[r][c] == '#') {
now = 0;
} else {
ans[r][c] += now;
now++;
}
if (board[H - r - 1][c] == '#') {
now_rev = 0;
} else {
ans[H - r - 1][c] += now_rev;
now_rev++;
}
}
}
int ans_val = 0;
REP(i, H) REP(j, W) ans_val = max(ans_val, ans[i][j]);
cout << ans_val << endl;
// REP(i, H) REP(j, W) cout << ans[i][j] << (j == W-1 ? '\n' : ' ');
return 0;
}
| [
"assignment.variable.change",
"identifier.change"
] | 828,198 | 828,199 | u315078622 | cpp |
p03014 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (auto i = 0; i < n; ++i)
#define REPR(i, n) for (auto i = n; i >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define FOR(i, a, b) for (auto i = a; i < b; ++i)
#define SORT(v, n) sort(v, v + n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(), v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n, v) \
{ \
int tmp; \
for (int i = 0; i < n; ++i) { \
scanf("%d", &tmp); \
v.push_back(tmp); \
} \
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
typedef pair<int, int> pii;
int h, w;
int light[2000][2000][4];
string s[2000];
int solve(int x, int y, int dir) {
// cout << x << " " << y << " " << dir << endl;
if (s[y][x] == '#') {
return 0;
}
int nx = x + dx[dir], ny = y + dy[dir];
if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
light[y][x][dir] = 1;
return 1;
}
if (light[ny][nx][dir] != 0) {
light[y][x][dir] = light[ny][nx][dir] + 1;
} else
light[y][x][dir] = solve(nx, ny, dir) + 1;
return light[y][x][dir];
}
int main() {
cin >> h >> w;
REP(i, h) { cin >> s[i]; }
REP(i, h) {
REP(j, w) {
REP(k, 4) { light[i][j][k] = 0; }
}
}
REP(i, h) {
REP(j, w) {
if (s[i][j] == '.') {
REP(k, 4) { solve(i, j, k); }
}
}
}
int ans = 0;
REP(i, h) {
REP(j, w) {
if (s[i][j] == '.') {
int num = 1;
REP(k, 4) {
int nx = j + dx[k], ny = i + dy[k];
if (nx >= 0 && nx < w && ny >= 0 && ny < h && light[ny][nx][k] != 0) {
num += light[ny][nx][k];
}
}
ans = max(ans, num);
}
}
}
/*
REP(i,h){
REP(j,w){
cout << light[i][j][0];
}
cout << endl;
}
*/
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (auto i = 0; i < n; ++i)
#define REPR(i, n) for (auto i = n; i >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define FOR(i, a, b) for (auto i = a; i < b; ++i)
#define SORT(v, n) sort(v, v + n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(), v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n, v) \
{ \
int tmp; \
for (int i = 0; i < n; ++i) { \
scanf("%d", &tmp); \
v.push_back(tmp); \
} \
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
typedef pair<int, int> pii;
int h, w;
int light[2000][2000][4];
string s[2000];
int solve(int x, int y, int dir) {
// cout << x << " " << y << " " << dir << endl;
if (s[y][x] == '#') {
return 0;
}
int nx = x + dx[dir], ny = y + dy[dir];
if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
light[y][x][dir] = 1;
return 1;
}
if (light[ny][nx][dir] != 0) {
light[y][x][dir] = light[ny][nx][dir] + 1;
} else
light[y][x][dir] = solve(nx, ny, dir) + 1;
return light[y][x][dir];
}
signed main() {
cin >> h >> w;
REP(i, h) { cin >> s[i]; }
REP(i, h) {
REP(j, w) {
REP(k, 4) { light[i][j][k] = 0; }
}
}
REP(i, h) {
REP(j, w) {
if (s[i][j] == '.') {
REP(k, 4) { solve(j, i, k); }
}
}
}
int ans = 0;
REP(i, h) {
REP(j, w) {
if (s[i][j] == '.') {
int num = 1;
REP(k, 4) {
int nx = j + dx[k], ny = i + dy[k];
if (nx >= 0 && nx < w && ny >= 0 && ny < h && light[ny][nx][k] != 0) {
num += light[ny][nx][k];
}
}
ans = max(ans, num);
}
}
}
/*
REP(i,h){
REP(j,w){
cout << light[i][j][0];
}
cout << endl;
}
*/
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"call.arguments.change",
"call.arguments.add"
] | 828,206 | 828,207 | u479953984 | cpp |
p03014 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vllin3(a, b, c, n) \
vll(a)(n); \
vll(b)(n); \
vll(c)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vlling(x, n) \
(x).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vlling2(a, b, n) \
(a).assign(n, 0); \
(b).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vlling3(a, b, c, n) \
(a).assign(n, 0); \
(b).assign(n, 0); \
(c).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(h);
llin(w);
vector<str> s(h, "");
FOR(i, 0, h - 1) { cin >> s[i]; }
vvll ws(h, vll(w, 0));
vvll hs(h, vll(w, 0));
vvll wr(h, vll(w + 1, 0));
vvll hr(h + 1, vll(w, 0));
ll t = 0;
ll c = 0;
FOR(i, 0, h - 1) {
t = 1;
c = 0;
FOR(j, 0, w - 1) {
if (s[i][j] == '#') {
wr[i][t] = c;
t++;
c = 0;
} else {
ws[i][j] = t;
c++;
}
}
wr[i][t] = c;
}
FOR(j, 0, w - 1) {
t = 1;
c = 0;
FOR(i, 0, h - 1) {
if (s[i][j] == '#') {
hr[t][j] = c;
t++;
c = 0;
} else {
hs[i][j] = t;
c++;
}
}
hr[t][j] = c;
}
ll k = 0;
FOR(i, 0, h - 1) {
FOR(j, 0, w - 1) {
if (s[i][j] == '.') {
k = max(wr[i][ws[i][j]] + hr[hs[i][j]][j], k);
}
}
}
sal(k - 1)
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vllin3(a, b, c, n) \
vll(a)(n); \
vll(b)(n); \
vll(c)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vlling(x, n) \
(x).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vlling2(a, b, n) \
(a).assign(n, 0); \
(b).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vlling3(a, b, c, n) \
(a).assign(n, 0); \
(b).assign(n, 0); \
(c).assign(n, 0); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(h);
llin(w);
vector<str> s(h, "");
FOR(i, 0, h - 1) { cin >> s[i]; }
vvll ws(h, vll(w, 0));
vvll hs(h, vll(w, 0));
vvll wr(h, vll(w + 2, 0));
vvll hr(h + 2, vll(w, 0));
ll t = 0;
ll c = 0;
FOR(i, 0, h - 1) {
t = 1;
c = 0;
FOR(j, 0, w - 1) {
if (s[i][j] == '#') {
wr[i][t] = c;
t++;
c = 0;
} else {
ws[i][j] = t;
c++;
}
}
wr[i][t] = c;
}
FOR(j, 0, w - 1) {
t = 1;
c = 0;
FOR(i, 0, h - 1) {
if (s[i][j] == '#') {
hr[t][j] = c;
t++;
c = 0;
} else {
hs[i][j] = t;
c++;
}
}
hr[t][j] = c;
}
ll k = 0;
FOR(i, 0, h - 1) {
FOR(j, 0, w - 1) {
if (s[i][j] == '.') {
k = max(wr[i][ws[i][j]] + hr[hs[i][j]][j], k);
}
}
}
sal(k - 1)
}
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 828,210 | 828,211 | u614421689 | cpp |
p03014 | #include <algorithm>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif
// ไบไนใ่จ็ฎใใใ
ll sq(ll x) { return x * x; }
// ้ ๅๅ
ใซใใใใ
bool within(ll x, ll min, ll max) { return min <= x && x <= max; }
// container ใฎไธญใใ key ใใๅฐใใๅคใ่ฆใคใใใ
// ่ฆใคใใใชใๅ ดๅใฏ container.end() ใ่ฟใใ
template <typename T>
typename T::iterator less_than(T &container, typename T::key_type &key) {
typename T::iterator prev = container.lower_bound(key);
if (prev == container.begin())
prev = container.end();
else
prev--;
return prev;
}
// container ใฎไธญใใ key ใใๅคงใใๅคใ่ฆใคใใใ
// ่ฆใคใใใชใๅ ดๅใฏ container.end() ใ่ฟใใ
template <typename T>
typename T::iterator greater_than(T &container, typename T::key_type &key) {
return container.upper_bound(key);
}
// b^e (mod m) ใๆฑใใ
ll modpow(ll b, ll e, ll m) {
ll result = 1;
while (e > 0) {
if ((e & 1) == 1)
result = (result * b) % m;
e >>= 1;
b = (b * b) % m;
}
return result;
}
// ใใใใ่งฃๆณ
int main(void) {
std::ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; ++i)
cin >> S[i];
vector<vector<int>> wmap;
wmap.resize(W);
for (int i = 0; i < W; ++i)
wmap[i].resize(H);
vector<vector<int>> hmap;
hmap.resize(H);
for (int i = 0; i < H; ++i)
hmap[i].resize(W);
for (int i = 0; i < W; ++i) {
int num = 0;
for (int j = 0; j < H; ++j) {
if (S[j][i] == '#')
num = 0;
else
num++;
wmap[i][j] = num;
}
num = wmap[i][H - 1];
for (int j = H - 1; j >= 0; --j) {
if (S[j][i] == '#')
num = 0;
else if (num == 0)
num = wmap[i][j];
wmap[i][j] = num;
}
}
for (int i = 0; i < H; ++i) {
int num = 0;
for (int j = 0; j < W; ++j) {
if (S[i][j] == '#')
num = 0;
else
num++;
hmap[i][j] = num;
}
num = hmap[i][H - 1];
for (int j = W - 1; j >= 0; --j) {
if (S[i][j] == '#')
num = 0;
else if (num == 0)
num = hmap[i][j];
hmap[i][j] = num;
}
}
int result = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
result = max(result, hmap[i][j] + wmap[j][i] - 1);
}
}
cout << result << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif
// ไบไนใ่จ็ฎใใใ
ll sq(ll x) { return x * x; }
// ้ ๅๅ
ใซใใใใ
bool within(ll x, ll min, ll max) { return min <= x && x <= max; }
// container ใฎไธญใใ key ใใๅฐใใๅคใ่ฆใคใใใ
// ่ฆใคใใใชใๅ ดๅใฏ container.end() ใ่ฟใใ
template <typename T>
typename T::iterator less_than(T &container, typename T::key_type &key) {
typename T::iterator prev = container.lower_bound(key);
if (prev == container.begin())
prev = container.end();
else
prev--;
return prev;
}
// container ใฎไธญใใ key ใใๅคงใใๅคใ่ฆใคใใใ
// ่ฆใคใใใชใๅ ดๅใฏ container.end() ใ่ฟใใ
template <typename T>
typename T::iterator greater_than(T &container, typename T::key_type &key) {
return container.upper_bound(key);
}
// b^e (mod m) ใๆฑใใ
ll modpow(ll b, ll e, ll m) {
ll result = 1;
while (e > 0) {
if ((e & 1) == 1)
result = (result * b) % m;
e >>= 1;
b = (b * b) % m;
}
return result;
}
// ใใใใ่งฃๆณ
int main(void) {
std::ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; ++i)
cin >> S[i];
vector<vector<int>> wmap;
wmap.resize(W);
for (int i = 0; i < W; ++i)
wmap[i].resize(H);
vector<vector<int>> hmap;
hmap.resize(H);
for (int i = 0; i < H; ++i)
hmap[i].resize(W);
for (int i = 0; i < W; ++i) {
int num = 0;
for (int j = 0; j < H; ++j) {
if (S[j][i] == '#')
num = 0;
else
num++;
wmap[i][j] = num;
}
num = wmap[i][H - 1];
for (int j = H - 1; j >= 0; --j) {
if (S[j][i] == '#')
num = 0;
else if (num == 0)
num = wmap[i][j];
wmap[i][j] = num;
}
}
for (int i = 0; i < H; ++i) {
int num = 0;
for (int j = 0; j < W; ++j) {
if (S[i][j] == '#')
num = 0;
else
num++;
hmap[i][j] = num;
}
num = hmap[i][W - 1];
for (int j = W - 1; j >= 0; --j) {
if (S[i][j] == '#')
num = 0;
else if (num == 0)
num = hmap[i][j];
hmap[i][j] = num;
}
}
int result = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
result = max(result, hmap[i][j] + wmap[j][i] - 1);
}
}
cout << result << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 828,220 | 828,221 | u609688888 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
const int N = 2050;
char g[N][N];
int n, m;
int le[N][N], ri[N][N], up[N][N], dw[N][N];
int main(void) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '#') {
le[i][j] = 0;
continue;
}
le[i][j] = 1;
if (j > 0 && g[i][j - 1] == '.') {
le[i][j] += le[i][j - 1];
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j > 0; j--) {
if (g[i][j] == '#') {
ri[i][j] = 0;
continue;
}
ri[i][j] = 1;
if (j < m - 1 && g[i][j + 1] == '.') {
ri[i][j] += ri[i][j + 1];
}
}
}
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// printf("%d ",ri[i][j]);
// }
// printf("\n");
// }
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (g[i][j] == '#') {
up[i][j] = 0;
continue;
}
up[i][j] = 1;
if (i > 0 && g[i - 1][j] == '.') {
up[i][j] += up[i - 1][j];
}
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 1; i > 0; i--) {
if (g[i][j] == '#') {
dw[i][j] = 0;
continue;
}
dw[i][j] = 1;
if (i < n - 1 && g[i + 1][j] == '.') {
dw[i][j] += dw[i + 1][j];
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '#') {
continue;
}
// printf("%d %d\n",i,j);
// if(i==1 && j==1){
// printf("%d %d %d %d\n",le[i][j],ri[i][j],up[i][j],dw[i][j]);
// }
ans = max(ans, le[i][j] + ri[i][j] + up[i][j] + dw[i][j] - 3);
// printf("%d\n",ans);
}
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2050;
char g[N][N];
int n, m;
int le[N][N], ri[N][N], up[N][N], dw[N][N];
int main(void) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '#') {
le[i][j] = 0;
continue;
}
le[i][j] = 1;
if (j > 0 && g[i][j - 1] == '.') {
le[i][j] += le[i][j - 1];
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
if (g[i][j] == '#') {
ri[i][j] = 0;
continue;
}
ri[i][j] = 1;
if (j < m - 1 && g[i][j + 1] == '.') {
ri[i][j] += ri[i][j + 1];
}
}
}
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// printf("%d ",ri[i][j]);
// }
// printf("\n");
// }
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (g[i][j] == '#') {
up[i][j] = 0;
continue;
}
up[i][j] = 1;
if (i > 0 && g[i - 1][j] == '.') {
up[i][j] += up[i - 1][j];
}
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 1; i >= 0; i--) {
if (g[i][j] == '#') {
dw[i][j] = 0;
continue;
}
dw[i][j] = 1;
if (i < n - 1 && g[i + 1][j] == '.') {
dw[i][j] += dw[i + 1][j];
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '#') {
continue;
}
// printf("%d %d\n",i,j);
// if(i==1 && j==1){
// printf("%d %d %d %d\n",le[i][j],ri[i][j],up[i][j],dw[i][j]);
// }
ans = max(ans, le[i][j] + ri[i][j] + up[i][j] + dw[i][j] - 3);
// printf("%d\n",ans);
}
}
printf("%d\n", ans);
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,224 | 828,225 | u978172081 | cpp |
p03014 | #include <bits/stdc++.h>
#ifdef DEBUG
#define PRINT(x) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " \
<< (x) << endl;
#define PRINTA(a, first, last) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \
<< (first) << ", " << (last) << ")" << endl; \
for (int i = (first); i < (last); ++i) { \
cout << #a << "[" << i << "] = " << (a)[i] << endl; \
}
#define PRINTP(p) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #p << " = (" \
<< (p.first) << ", " << (p.second) << ")" << endl;
#define PRINTI(a, i) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \
<< #i << "] = " << #a << "[" << (i) << "] = " << (a)[i] << endl;
#else
#define PRINT(x)
#define PRINTA(a, first, last)
#define PRINTP(p)
#define PRINTI(a, i)
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T, class U> void amax(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void amin(T &x, U y) {
if (x > y)
x = y;
}
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
REP(i, H) cin >> S[i];
vector<vector<int>> left(H), right(H), up(H), down(H);
REP(i, H) {
left[i].resize(W);
right[i].resize(W);
up[i].resize(W);
down[i].resize(W);
}
REP(i, H) REP(j, W) {
if (j == 0) {
left[i][j] = 0;
} else {
if (S[i][j - 1] == '.') {
left[i][j] = 1 + left[i][j - 1];
} else {
left[i][j] = 0;
}
}
if (i == 0) {
up[i][j] = 0;
} else {
if (S[i - 1][j] == '.') {
up[i][j] = 1 + up[i - 1][j];
} else {
up[i][j] = 0;
}
}
}
RREP(i, H) RREP(j, W) {
if (j == W - 1) {
right[i][j] = 0;
} else {
if (S[i][j + 1] == '.') {
right[i][j] = 1 + right[i][j + 1];
} else {
right[i][j] = 0;
}
}
if (i == H - 1) {
down[i][j] = 0;
} else {
if (S[i + 1][j] == '.') {
down[i][j] = 1 + down[i + 1][j];
} else {
down[i][j] = 0;
}
}
}
int result = 0;
REP(i, H) REP(j, H) {
if (S[i][j] == '.') {
amax(result, 1 + left[i][j] + right[i][j] + up[i][j] + down[i][j]);
}
}
cout << result << endl;
return 0;
}
| #include <bits/stdc++.h>
#ifdef DEBUG
#define PRINT(x) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " \
<< (x) << endl;
#define PRINTA(a, first, last) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \
<< (first) << ", " << (last) << ")" << endl; \
for (int i = (first); i < (last); ++i) { \
cout << #a << "[" << i << "] = " << (a)[i] << endl; \
}
#define PRINTP(p) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #p << " = (" \
<< (p.first) << ", " << (p.second) << ")" << endl;
#define PRINTI(a, i) \
cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" \
<< #i << "] = " << #a << "[" << (i) << "] = " << (a)[i] << endl;
#else
#define PRINT(x)
#define PRINTA(a, first, last)
#define PRINTP(p)
#define PRINTI(a, i)
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T, class U> void amax(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void amin(T &x, U y) {
if (x > y)
x = y;
}
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
REP(i, H) cin >> S[i];
vector<vector<int>> left(H), right(H), up(H), down(H);
REP(i, H) {
left[i].resize(W);
right[i].resize(W);
up[i].resize(W);
down[i].resize(W);
}
REP(i, H) REP(j, W) {
if (j == 0) {
left[i][j] = 0;
} else {
if (S[i][j - 1] == '.') {
left[i][j] = 1 + left[i][j - 1];
} else {
left[i][j] = 0;
}
}
if (i == 0) {
up[i][j] = 0;
} else {
if (S[i - 1][j] == '.') {
up[i][j] = 1 + up[i - 1][j];
} else {
up[i][j] = 0;
}
}
}
RREP(i, H) RREP(j, W) {
if (j == W - 1) {
right[i][j] = 0;
} else {
if (S[i][j + 1] == '.') {
right[i][j] = 1 + right[i][j + 1];
} else {
right[i][j] = 0;
}
}
if (i == H - 1) {
down[i][j] = 0;
} else {
if (S[i + 1][j] == '.') {
down[i][j] = 1 + down[i + 1][j];
} else {
down[i][j] = 0;
}
}
}
int result = 0;
REP(i, H) REP(j, W) {
if (S[i][j] == '.') {
amax(result, 1 + left[i][j] + right[i][j] + up[i][j] + down[i][j]);
}
}
cout << result << endl;
return 0;
}
| [] | 828,228 | 828,229 | u537859408 | cpp |
p03014 | #include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define pri 1000000007
#define nonod 1000001
#define pr pair<ll, ll>
#define mnx 1000001
#define inf 100000000000000001
#define prin(x) cout << setprecision(9) << fixed << x << endl;
using namespace std;
void masterstroke(ll ta) {
ll h, w;
cin >> h >> w;
ll dp[h][w];
string a[h];
vector<ll> col[w], row[h];
for (ll i = 0; i < w; i++) {
col[i].PB(-1);
}
for (ll i = 0; i < h; i++) {
row[i].PB(-1);
}
for (ll i = 0; i < h; i++) {
cin >> a[i];
for (ll j = 0; j < w; j++) {
if (a[i][j] == '#') {
row[i].PB(j);
col[j].PB(i);
}
// if(a[i][j]=='.')row[j]
}
}
for (ll i = 0; i < w; i++) {
col[i].PB(h);
}
for (ll i = 0; i < h; i++) {
row[i].PB(w);
}
ll mx = 0;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (a[i][j] == '.') {
auto ze = upper_bound(all(row[i]), j);
ll x1 = *ze;
ze--;
ll x2 = *ze;
auto zee = upper_bound(all(col[j]), j);
ll y1 = *zee;
zee--;
ll y2 = *zee;
ll ans = abs(y2 - y1) - 1 + abs(x2 - x1) - 1 - 1;
mx = max(mx, ans);
}
}
}
cout << mx << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++)
masterstroke(i);
} | #include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define pri 1000000007
#define nonod 1000001
#define pr pair<ll, ll>
#define mnx 1000001
#define inf 100000000000000001
#define prin(x) cout << setprecision(9) << fixed << x << endl;
using namespace std;
void masterstroke(ll ta) {
ll h, w;
cin >> h >> w;
ll dp[h][w];
string a[h];
vector<ll> col[w], row[h];
for (ll i = 0; i < w; i++) {
col[i].PB(-1);
}
for (ll i = 0; i < h; i++) {
row[i].PB(-1);
}
for (ll i = 0; i < h; i++) {
cin >> a[i];
for (ll j = 0; j < w; j++) {
if (a[i][j] == '#') {
row[i].PB(j);
col[j].PB(i);
}
// if(a[i][j]=='.')row[j]
}
}
for (ll i = 0; i < w; i++) {
col[i].PB(h);
}
for (ll i = 0; i < h; i++) {
row[i].PB(w);
}
ll mx = 0;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (a[i][j] == '.') {
// cout<<i<<j<<endl;
auto ze = upper_bound(all(row[i]), j);
ll x1 = *ze;
ze--;
ll x2 = *ze;
auto zee = upper_bound(all(col[j]), i);
ll y1 = *zee;
zee--;
ll y2 = *zee;
// cout<<x2<<x1<<y1<<y2<<endl;
ll ans = abs(y2 - y1) - 1 + abs(x2 - x1) - 1 - 1;
mx = max(mx, ans);
}
}
}
cout << mx << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++)
masterstroke(i);
} | [
"identifier.change",
"call.arguments.change"
] | 828,232 | 828,233 | u874786170 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long MOD = 1000000007LL;
const long INF = 1e8;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
int h, w;
cin >> h >> w;
char s[h][w];
long d[h][w];
rep(i, h) {
rep(j, w) { d[i][j] = 0; }
}
string ss;
rep(i, h) {
cin >> ss;
rep(j, w) { s[i][j] = ss[j]; }
}
int tem = -1;
rep(i, h) {
tem = -1;
rep(j, w) {
if (s[i][j] == '#') {
d[i][j] = -INF;
tem = j;
} else {
d[i][j] += (j - tem);
}
}
tem = w;
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '#') {
d[i][j] = -INF;
tem = j;
} else {
d[i][j] += (tem - j);
}
}
rep(j, w) { d[i][j]--; }
}
rep(i, w) {
tem = -1;
rep(j, h) {
if (s[j][i] == '#') {
d[j][i] = -INF;
tem = j;
} else {
d[j][i] += (j - tem);
}
}
tem = h;
for (int j = h - 1; j >= 0; j--) {
if (s[j][i] == '#') {
d[j][i] = -INF;
tem = j;
} else {
d[j][i] += (tem - j);
}
}
rep(j, w) { d[j][i]--; }
}
long ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, d[i][j]); }
}
cout << ans - 1 << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long MOD = 1000000007LL;
const long INF = 1e5;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
int h, w;
cin >> h >> w;
char s[h][w];
long d[h][w];
rep(i, h) {
rep(j, w) { d[i][j] = 0; }
}
string ss;
rep(i, h) {
cin >> ss;
rep(j, w) { s[i][j] = ss[j]; }
}
int tem = -1;
rep(i, h) {
tem = -1;
rep(j, w) {
if (s[i][j] == '#') {
d[i][j] = -INF;
tem = j;
} else {
d[i][j] += (j - tem);
}
}
tem = w;
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '#') {
d[i][j] = -INF;
tem = j;
} else {
d[i][j] += (tem - j);
}
}
rep(j, w) { d[i][j]--; }
}
rep(i, w) {
tem = -1;
rep(j, h) {
if (s[j][i] == '#') {
d[j][i] = -INF;
tem = j;
} else {
d[j][i] += (j - tem);
}
}
tem = h;
for (int j = h - 1; j >= 0; j--) {
if (s[j][i] == '#') {
d[j][i] = -INF;
tem = j;
} else {
d[j][i] += (tem - j);
}
}
rep(j, h) { d[j][i]--; }
}
long ans = 0;
rep(i, h) {
rep(j, w) { ans = max(ans, d[i][j]); }
}
cout << ans - 1 << endl;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 828,234 | 828,235 | u467826805 | cpp |
p03014 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
REP(i, v.size()) {
if (i)
os << endl;
os << v[i];
}
return os;
}
const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
#define int long long
inline void my_io() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cout << fixed << setprecision(16);
// cout << setprecision(10) << scientific << ans << endl;
}
signed main() {
ll h, w;
cin >> h >> w;
vector<string> v(h, "");
REP(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, 0));
vector<vector<ll>> b(h, vector<ll>(w, 0));
REP(i, h) {
ll sum = 0;
ll start = 0;
REP(j, w) {
if (v[i][j] == '#') {
FOR(k, start, j) { a[i][k] = sum; }
sum = 0;
start = j + 1;
} else if (j == w - 1) {
sum++;
FOR(k, start, j) { a[i][k] = sum; }
} else {
sum++;
}
}
}
REP(i, w) {
ll sum = 0;
ll start = 0;
REP(j, h) {
if (v[j][i] == '#') {
FOR(k, start, j) { b[k][i] = sum; }
sum = 0;
start = j + 1;
} else if (j == h - 1) {
sum++;
FOR(k, start, j) { b[k][i] = sum; }
} else {
sum++;
}
}
}
ll ans = 0;
REP(i, h) {
REP(j, w) { ans = max(ans, a[i][j] + b[i][j] - 1); }
}
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
REP(i, v.size()) {
if (i)
os << endl;
os << v[i];
}
return os;
}
const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
#define int long long
inline void my_io() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cout << fixed << setprecision(16);
// cout << setprecision(10) << scientific << ans << endl;
}
signed main() {
ll h, w;
cin >> h >> w;
vector<string> v(h, "");
REP(i, h) { cin >> v[i]; }
vector<vector<ll>> a(h, vector<ll>(w, 0));
vector<vector<ll>> b(h, vector<ll>(w, 0));
REP(i, h) {
ll sum = 0;
ll start = 0;
REP(j, w) {
if (v[i][j] == '#') {
FOR(k, start, j) { a[i][k] = sum; }
sum = 0;
start = j + 1;
} else if (j == w - 1) {
sum++;
FOR(k, start, j + 1) { a[i][k] = sum; }
} else {
sum++;
}
}
}
REP(i, w) {
ll sum = 0;
ll start = 0;
REP(j, h) {
if (v[j][i] == '#') {
FOR(k, start, j) { b[k][i] = sum; }
sum = 0;
start = j + 1;
} else if (j == h - 1) {
sum++;
FOR(k, start, j + 1) { b[k][i] = sum; }
} else {
sum++;
}
}
}
ll ans = 0;
REP(i, h) {
REP(j, w) { ans = max(ans, a[i][j] + b[i][j] - 1); }
}
cout << ans << endl;
} | [
"expression.operation.binary.add"
] | 828,238 | 828,239 | u800551451 | cpp |
p03014 | #include <cstdio>
#include <cstring>
using namespace std;
const int N = 2'009;
char a[N][N];
int f[N][N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", a[i]);
}
memset(f, 0, sizeof f);
for (int i = 0; i < n; ++i) {
{
int cnt = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
{
int cnt = 0;
for (int j = m - 1; j >= 0; --j) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
}
for (int j = 0; j < m; ++j) {
{
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
{
int cnt = 0;
for (int i = n - 1; i >= 0; --i) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i][j] == '.') {
if (f[i][j] + 1 > ans) {
ans = f[i][j] + 1;
}
}
}
}
printf("%d\n", ans);
}
| #include <cstdio>
#include <cstring>
using namespace std;
const int N = 2'009;
char a[N][N];
int f[N][N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%s", a[i]);
}
memset(f, 0, sizeof f);
for (int i = 0; i < n; ++i) {
{
int cnt = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
{
int cnt = 0;
for (int j = m - 1; j >= 0; --j) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
}
for (int j = 0; j < m; ++j) {
{
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
{
int cnt = 0;
for (int i = n - 1; i >= 0; --i) {
if (a[i][j] == '.') {
f[i][j] += cnt;
++cnt;
} else {
cnt = 0;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '.') {
if (f[i][j] + 1 > ans) {
ans = f[i][j] + 1;
}
}
}
}
printf("%d\n", ans);
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,242 | 828,243 | u127130661 | cpp |
p03014 | #include <bits/stdc++.h>
#define mxn 2010
using namespace std;
int n, m, sl, fh, ans, l[mxn][mxn], r[mxn][mxn], u[mxn][mxn], d[mxn][mxn];
char s[mxn][mxn];
int rd() {
sl = 0;
fh = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-')
fh = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9')
sl = sl * 10 + ch - '0', ch = getchar();
return sl * fh;
}
int main() {
n = rd();
m = rd();
for (int i = 1; i <= n; ++i)
scanf("%s", s[i] + 1);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1;
else
l[i][j] = 0;
for (int i = 1; i <= n; ++i)
for (int j = m; j; --j)
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1;
else
r[i][j] = 0;
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= n; ++j)
if (s[j][i] == '.')
u[j][i] = u[j - 1][i] + 1;
else
u[j][i] = 0;
for (int i = 1; i <= m; ++i)
for (int j = n; j; --j)
if (s[j][i] == '.')
d[j][i] = d[j + 1][i] + 1;
else
d[j][i] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define mxn 2010
using namespace std;
int n, m, sl, fh, ans, l[mxn][mxn], r[mxn][mxn], u[mxn][mxn], d[mxn][mxn];
char s[mxn][mxn];
int rd() {
sl = 0;
fh = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-')
fh = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9')
sl = sl * 10 + ch - '0', ch = getchar();
return sl * fh;
}
int main() {
n = rd();
m = rd();
for (int i = 1; i <= n; ++i)
scanf("%s", s[i] + 1);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (s[i][j] == '.')
l[i][j] = l[i][j - 1] + 1;
else
l[i][j] = 0;
for (int i = 1; i <= n; ++i)
for (int j = m; j; --j)
if (s[i][j] == '.')
r[i][j] = r[i][j + 1] + 1;
else
r[i][j] = 0;
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= n; ++j)
if (s[j][i] == '.')
u[j][i] = u[j - 1][i] + 1;
else
u[j][i] = 0;
for (int i = 1; i <= m; ++i)
for (int j = n; j; --j)
if (s[j][i] == '.')
d[j][i] = d[j + 1][i] + 1;
else
d[j][i] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
printf("%d\n", ans);
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,246 | 828,247 | u938301018 | cpp |
p03014 | #include <iostream>
int main() {
int H, W;
scanf("%d %d", &H, &W);
char S[H][W + 1];
for (int i = 0; i < H; i++)
scanf(" %s", S[i]);
int count_v[H][W];
for (int i = 0; i < H; i++) {
int mode = 0;
int start = 0;
for (int j = 0; j < W; j++) {
if (S[i][j] == '#')
count_v[i][j] = 0;
if (mode == 0) {
if (S[i][j] == '.') {
start = j;
mode = 1;
if (j == W - 1)
count_v[i][j] = 1;
}
}
if (mode == 1) {
if (S[i][j] == '#') {
int c = j - start;
for (int k = start; k < j; k++)
count_v[i][k] = c;
mode = 0;
} else if (j == W - 1) {
int c = W - start;
for (int k = start; k < W; k++)
count_v[i][k] = c;
}
}
}
}
int count_h[H][W];
for (int j = 0; j < H; j++) {
int mode = 0;
int start = 0;
for (int i = 0; i < H; i++) {
if (S[i][j] == '#')
count_h[i][j] = 0;
if (mode == 0) {
if (S[i][j] == '.') {
start = i;
mode = 1;
if (i == H - 1)
count_h[i][j] = 1;
}
}
if (mode == 1) {
if (S[i][j] == '#') {
int c = i - start;
for (int k = start; k < i; k++)
count_h[k][j] = c;
mode = 0;
} else if (i == H - 1) {
int c = H - start;
for (int k = start; k < H; k++)
count_h[k][j] = c;
}
}
}
}
int max = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int count = count_v[i][j] + count_h[i][j] - 1;
if (count > max)
max = count;
}
}
printf("%d\n", max);
} | #include <iostream>
int main() {
int H, W;
scanf("%d %d", &H, &W);
char S[H][W + 1];
for (int i = 0; i < H; i++)
scanf(" %s", S[i]);
int count_v[H][W];
for (int i = 0; i < H; i++) {
int mode = 0;
int start = 0;
for (int j = 0; j < W; j++) {
if (S[i][j] == '#')
count_v[i][j] = 0;
if (mode == 0) {
if (S[i][j] == '.') {
start = j;
mode = 1;
if (j == W - 1)
count_v[i][j] = 1;
}
}
if (mode == 1) {
if (S[i][j] == '#') {
int c = j - start;
for (int k = start; k < j; k++)
count_v[i][k] = c;
mode = 0;
} else if (j == W - 1) {
int c = W - start;
for (int k = start; k < W; k++)
count_v[i][k] = c;
}
}
}
}
int count_h[H][W];
for (int j = 0; j < W; j++) {
int mode = 0;
int start = 0;
for (int i = 0; i < H; i++) {
if (S[i][j] == '#')
count_h[i][j] = 0;
if (mode == 0) {
if (S[i][j] == '.') {
start = i;
mode = 1;
if (i == H - 1)
count_h[i][j] = 1;
}
}
if (mode == 1) {
if (S[i][j] == '#') {
int c = i - start;
for (int k = start; k < i; k++)
count_h[k][j] = c;
mode = 0;
} else if (i == H - 1) {
int c = H - start;
for (int k = start; k < H; k++)
count_h[k][j] = c;
}
}
}
}
int max = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int count = count_v[i][j] + count_h[i][j] - 1;
if (count > max)
max = count;
}
}
printf("%d\n", max);
/*
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
std::cout << count_v[i][j];
}
std::cout << std::endl;
}
std::cout << std::endl;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
std::cout << count_h[i][j];
}
std::cout << std::endl;
}
*/
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,262 | 828,263 | u440312135 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w;
else {
auto itr = upper_bound(all(row[i]), i);
if (itr == row[i].end()) {
tmp += (w - j);
} else {
tmp += (*itr - j);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp);
}
}
}
cout << mx << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w;
else {
auto itr = upper_bound(all(row[i]), j);
if (itr == row[i].end()) {
tmp += (w - j);
} else {
tmp += (*itr - j);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp);
}
}
}
cout << mx << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 828,264 | 828,265 | u218759384 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w;
else {
auto itr = upper_bound(all(row[i]), i);
if (itr == row[i].end()) {
tmp += (w - j);
} else {
tmp += (*itr - j);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]));
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]));
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp);
}
}
}
cout << mx << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w;
else {
auto itr = upper_bound(all(row[i]), j);
if (itr == row[i].end()) {
tmp += (w - j);
} else {
tmp += (*itr - j);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp);
}
}
}
cout << mx << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 828,266 | 828,265 | u218759384 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w - 1;
else {
auto itr = upper_bound(all(row[i]), i);
if (itr == row[i].end()) {
tmp += (w - j - 1);
} else {
tmp += (*itr - j - 1);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp + 1);
}
}
}
cout << mx << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 2; i < 3; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 0; j < 1; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w - 1;
else {
auto itr = upper_bound(all(row[i]), j);
if (itr == row[i].end()) {
// cout << "c" << endl;
tmp += (w - j - 1);
} else {
// cout << "cc" << *itr << endl;
tmp += (*itr - j - 1);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp + 1 << endl;
mx = max(mx, tmp + 1);
}
}
}
cout << mx << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 828,267 | 828,268 | u218759384 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 1; i < 2; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 1; j < 2; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w - 1;
else {
auto itr = upper_bound(all(row[i]), i);
if (itr == row[i].end()) {
tmp += (w - j - 1);
} else {
tmp += (*itr - j - 1);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
mx = max(mx, tmp);
}
}
}
cout << mx << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int h, w;
string s[2000];
cin >> h >> w;
for (int i = 0; i < h; i++)
cin >> s[i];
vector<vector<int>> row, cul;
// cout << "a" << endl;
for (int i = 0; i < h; i++) {
vector<int> tmp;
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
tmp.push_back(j);
}
row.push_back(tmp);
}
// cout << "a" << endl;
for (int i = 0; i < w; i++) {
vector<int> tmp;
for (int j = 0; j < h; j++) {
if (s[j][i] == '#') {
tmp.push_back(j);
// cout << "(" << j << "," << i << ")" << endl;
}
}
cul.push_back(tmp);
}
// cout << "a" << endl;
// for (int i = 0; i < w; i++)
// {
// for (int j = 0; j < cul[i].size(); j++)
// cout << cul[i][j] << " ";
// cout << endl;
// }
int mx = -1;
for (int i = 0; i < h; i++)
// for (int i = 2; i < 3; i++)
{
for (int j = 0; j < w; j++)
// for (int j = 0; j < 1; j++)
{
int tmp = 0;
if (s[i][j] != '#') {
// row
if (row[i].size() == 0)
tmp += w - 1;
else {
auto itr = upper_bound(all(row[i]), j);
if (itr == row[i].end()) {
// cout << "c" << endl;
tmp += (w - j - 1);
} else {
// cout << "cc" << *itr << endl;
tmp += (*itr - j - 1);
}
if (itr - row[i].begin() == 0) {
// cout << "a";
tmp += j;
} else {
tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
}
}
// cout << "=" << tmp << endl;
// cul
if (cul[j].size() == 0)
tmp += (h - 1);
else {
auto itr = upper_bound(all(cul[j]), i);
if (itr == cul[j].end()) {
tmp += (h - i - 1);
} else {
tmp += (*itr - i - 1);
}
if (itr - cul[j].begin() == 0) {
tmp += i;
} else {
tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
}
}
// cout << "=" << tmp + 1 << endl;
mx = max(mx, tmp + 1);
}
}
}
cout << mx << endl;
} | [
"identifier.change",
"call.arguments.change",
"assignment.change"
] | 828,269 | 828,268 | u218759384 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int grid[2000 + 1 + 1][2000 + 1 + 1];
int L[2000 + 1 + 1][2000 + 1 + 1];
int R[2000 + 1 + 1][2000 + 1 + 1];
int U[2000 + 1 + 1][2000 + 1 + 1];
int D[2000 + 1 + 1][2000 + 1 + 1];
int main() {
int H, W;
cin >> H >> W;
for (int i = 1; i <= H; ++i) {
string s;
cin >> s;
for (int j = 1; j <= W; ++j) {
if (s[j - 1] == '#')
grid[i][j] = 1;
}
}
for (int i = 1; i <= H; ++i) {
if (grid[i][1] == 0)
L[i][1] = 1;
for (int j = 2; j <= W; ++j) {
if (grid[i][j] == 0)
L[i][j] = L[i][j - 1] + 1;
}
}
for (int i = 1; i <= H; ++i) {
if (grid[i][W] == 0)
R[i][W] = 1;
for (int j = W - 1; j >= 1; --j) {
if (grid[i][j] == 0)
R[i][j] = R[i][j + 1] + 1;
}
}
for (int i = 1; i <= W; ++i) {
if (grid[1][i] == 0)
U[1][i] = 1;
for (int j = 2; j <= H; ++j) {
if (grid[j][i] == 0)
U[j][i] = U[j - 1][i] + 1;
}
}
for (int i = 1; i <= W; ++i) {
if (grid[H][i] == 0)
D[H][i] = 1;
for (int j = H - 1; j >= 1; --j) {
if (grid[j][i] == 0)
D[j][i] = D[j + 1][i] + 1;
}
}
int ans = 1 << 30;
for (int i = 1; i <= H; ++i) {
for (int j = 1; j <= W; ++j) {
if (grid[i][j] == 0)
ans = min(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int grid[2000 + 1 + 1][2000 + 1 + 1];
int L[2000 + 1 + 1][2000 + 1 + 1];
int R[2000 + 1 + 1][2000 + 1 + 1];
int U[2000 + 1 + 1][2000 + 1 + 1];
int D[2000 + 1 + 1][2000 + 1 + 1];
int main() {
int H, W;
cin >> H >> W;
for (int i = 1; i <= H; ++i) {
string s;
cin >> s;
for (int j = 1; j <= W; ++j) {
if (s[j - 1] == '#')
grid[i][j] = 1;
}
}
for (int i = 1; i <= H; ++i) {
if (grid[i][1] == 0)
L[i][1] = 1;
for (int j = 2; j <= W; ++j) {
if (grid[i][j] == 0)
L[i][j] = L[i][j - 1] + 1;
}
}
for (int i = 1; i <= H; ++i) {
if (grid[i][W] == 0)
R[i][W] = 1;
for (int j = W - 1; j >= 1; --j) {
if (grid[i][j] == 0)
R[i][j] = R[i][j + 1] + 1;
}
}
for (int i = 1; i <= W; ++i) {
if (grid[1][i] == 0)
U[1][i] = 1;
for (int j = 2; j <= H; ++j) {
if (grid[j][i] == 0)
U[j][i] = U[j - 1][i] + 1;
}
}
for (int i = 1; i <= W; ++i) {
if (grid[H][i] == 0)
D[H][i] = 1;
for (int j = H - 1; j >= 1; --j) {
if (grid[j][i] == 0)
D[j][i] = D[j + 1][i] + 1;
}
}
int ans = 0;
for (int i = 1; i <= H; ++i) {
for (int j = 1; j <= W; ++j) {
if (grid[i][j] == 0)
ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
}
}
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 828,272 | 828,273 | u577747009 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int L[2000][2000], R[2000][2000];
int D[2000][2000], U[2000][2000];
int main() {
int h, w;
cin >> h >> w;
string s[h];
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] == '#') {
U[i][j] = L[i][j] = 0;
continue;
}
if (i == 0) {
U[i][j] = 1;
} else {
U[i][j] = U[i - 1][j] + 1;
}
if (j == 0) {
L[i][j] = 1;
} else {
L[i][j] = L[i][j - 1] + 1;
}
}
}
for (int i = h - 1; i >= 0; i--) {
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '#') {
D[i][j] = R[i][j] = 0;
continue;
}
if (i == h - 1) {
D[i][j] = 1;
} else {
D[i][j] = D[i + 1][j] + 1;
}
if (j == w - 1) {
R[i][j] = 1;
} else {
R[i][j] = R[i][j + 1] + 1;
}
}
}
int ans = -INF;
for (int i = 0; i < h; i++) {
for (int j = 0; j < h; j++) {
ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int L[2000][2000], R[2000][2000];
int D[2000][2000], U[2000][2000];
int main() {
int h, w;
cin >> h >> w;
string s[h];
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] == '#') {
U[i][j] = L[i][j] = 0;
continue;
}
if (i == 0) {
U[i][j] = 1;
} else {
U[i][j] = U[i - 1][j] + 1;
}
if (j == 0) {
L[i][j] = 1;
} else {
L[i][j] = L[i][j - 1] + 1;
}
}
}
for (int i = h - 1; i >= 0; i--) {
for (int j = w - 1; j >= 0; j--) {
if (s[i][j] == '#') {
D[i][j] = R[i][j] = 0;
continue;
}
if (i == h - 1) {
D[i][j] = 1;
} else {
D[i][j] = D[i + 1][j] + 1;
}
if (j == w - 1) {
R[i][j] = 1;
} else {
R[i][j] = R[i][j + 1] + 1;
}
}
}
int ans = -INF;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
}
}
cout << ans << endl;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 828,274 | 828,275 | u708258059 | cpp |
p03014 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;
string s[2000];
int ans = 0, h, w;
int L[2000][2000] = {0};
int R[2000][2000] = {0};
int D[2000][2000] = {0};
int U[2000][2000] = {0};
int main() {
cin >> h >> w;
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 (i == 0)
U[i][j] = (0 + 1) * (s[i][j] == '.');
else
U[i][j] = (U[i - 1][j] + 1) * (s[i][j] == '.');
if (j == 0)
L[i][j] = (0 + 1) * (s[i][j] == '.');
else
L[i][j] = (L[i][j - 1] + 1) * (s[i][j] == '.');
}
}
for (int i = h - 1; i >= 0; i--) {
for (int j = w - 1; j >= 0; j--) {
if (i == h - 1)
D[i][j] = (0 + 1) * (s[i][j] == '.');
else
D[i][j] = (D[i + 1][j] + 1) * (s[i][j] == '.');
if (j == w - 1)
L[i][j] = (0 + 1) * (s[i][j] == '.');
else
R[i][j] = (R[i][j + 1] + 1) * (s[i][j] == '.');
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j]);
}
}
// for(int i = 0; i < h; i++){
// for(int j = 0; j < w; j++){
// printf("%.2d ", U[i][j]);
// }
// cout << endl;
// }
cout << ans - 3;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;
string s[2000];
int ans = 0, h, w;
int L[2000][2000] = {0};
int R[2000][2000] = {0};
int D[2000][2000] = {0};
int U[2000][2000] = {0};
int main() {
cin >> h >> w;
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 (i == 0)
U[i][j] = (0 + 1) * (s[i][j] == '.');
else
U[i][j] = (U[i - 1][j] + 1) * (s[i][j] == '.');
if (j == 0)
L[i][j] = (0 + 1) * (s[i][j] == '.');
else
L[i][j] = (L[i][j - 1] + 1) * (s[i][j] == '.');
}
}
for (int i = h - 1; i >= 0; i--) {
for (int j = w - 1; j >= 0; j--) {
if (i == h - 1)
D[i][j] = (0 + 1) * (s[i][j] == '.');
else
D[i][j] = (D[i + 1][j] + 1) * (s[i][j] == '.');
if (j == w - 1)
R[i][j] = (0 + 1) * (s[i][j] == '.');
else
R[i][j] = (R[i][j + 1] + 1) * (s[i][j] == '.');
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j]);
}
}
// for(int i = 0; i < h; i++){
// for(int j = 0; j < w; j++){
// printf("%.2d ", L[i][j]);
// }
// cout << endl;
// }
cout << ans - 3;
return 0;
}
| [
"assignment.variable.change",
"identifier.change"
] | 828,278 | 828,279 | u261245192 | cpp |
p03014 | #include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;
int H, W;
string S[2010];
int L[2010][2010];
int R[2010][2010];
int U[2010][2010];
int D[2010][2010];
int main() {
cin >> H >> W;
REP(i, 0, H) cin >> S[i];
// i่ก็ฎใซใคใใฆ:
REP(i, 0, H) {
// L[i][j]: j-1ๅ็ฎใพใง; (i,j)ใซๅฑ
ใใจใใฎๅทฆใฎ.
L[i][0] = 0; // left
REP(j, 1, W) {
if (S[i][j - 1] == '.')
L[i][j] = L[i][j - 1] + 1;
else
L[i][j] = 0; // reset if #
// printf("(%d,%d) -> %d\n", i, j, L[i][j]);
}
// R[i][j]: j+1ๅ็ฎใใ; (i,j)ใซๅฑ
ใใจใใฎๅณ
R[i][W - 1] = 0;
RREP(j, W - 1, 0) { // W-2ใใ
if (S[i][j + 1] == '.')
R[i][j] = R[i][j + 1] + 1;
else
R[i][j] = 0;
// printf("(%d,%d) -> %d\n", i, j, R[i][j]);
}
}
// jๅ็ฎใซใคใใฆ: (ไธไธ)
REP(j, 0, W) {
U[0][j] = 0; // Up
REP(i, 1, H - 1) {
if (S[i - 1][j] == '.')
U[i][j] = U[i - 1][j] + 1;
else
U[i][j] = 0;
}
D[H - 1][j] = 0; // Down
RREP(i, H - 1, 0) {
if (S[i + 1][j] == '.')
D[i][j] = D[i + 1][j] + 1;
else
D[i][j] = 0;
}
}
// ** ่จ็ฎ
int ans = -1; // ็
งใใใใใในใฎๅๆฐใฎๆๅคงๅค
REP(i, 0, H) REP(j, 0, W) {
// ไธไธๅทฆๅณ4ๆนๅ
// ้ๅฎณ็ฉใฎใชใใในใใ
if (S[i][j] == '.')
chmax(ans, 1 + L[i][j] + R[i][j] + U[i][j] + D[i][j]);
}
assert(ans >= 1);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;
int H, W;
string S[2010];
int L[2010][2010];
int R[2010][2010];
int U[2010][2010];
int D[2010][2010];
int main() {
cin >> H >> W;
REP(i, 0, H) cin >> S[i];
// i่ก็ฎใซใคใใฆ:
REP(i, 0, H) {
// L[i][j]: j-1ๅ็ฎใพใง; (i,j)ใซๅฑ
ใใจใใฎๅทฆใฎ.
L[i][0] = 0; // left
REP(j, 1, W) {
// ๅทฆใฎใใน
if (S[i][j - 1] == '.')
L[i][j] = L[i][j - 1] + 1;
else
L[i][j] = 0; // reset if #
// printf("(%d,%d) -> %d\n", i, j, L[i][j]);
}
// R[i][j]: j+1ๅ็ฎใใ; (i,j)ใซๅฑ
ใใจใใฎๅณ
R[i][W - 1] = 0;
RREP(j, W - 1, 0) { // W-2ใใ
// ๅณใฎใใน
if (S[i][j + 1] == '.')
R[i][j] = R[i][j + 1] + 1;
else
R[i][j] = 0;
// printf("(%d,%d) -> %d\n", i, j, R[i][j]);
}
}
// jๅ็ฎใซใคใใฆ: (ไธไธ)
REP(j, 0, W) {
U[0][j] = 0; // Up
REP(i, 1, H) {
// ไธใฎใใน
if (S[i - 1][j] == '.')
U[i][j] = U[i - 1][j] + 1;
else
U[i][j] = 0;
}
D[H - 1][j] = 0; // Down
RREP(i, H - 1, 0) {
// ไธใฎใใน
if (S[i + 1][j] == '.')
D[i][j] = D[i + 1][j] + 1;
else
D[i][j] = 0;
}
}
// ** ่จ็ฎ
int ans = -1; // ็
งใใใใใในใฎๅๆฐใฎๆๅคงๅค
REP(i, 0, H) REP(j, 0, W) {
// ไธไธๅทฆๅณ4ๆนๅ
// ้ๅฎณ็ฉใฎใชใใในใใ
// ๆใใใ่จญ็ฝฎใใใในใ็
งใใใ
if (S[i][j] == '.')
chmax(ans, 1 + L[i][j] + R[i][j] + U[i][j] + D[i][j]);
}
assert(ans >= 1);
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 828,288 | 828,289 | u803116068 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORR(x, arr) for (auto &x : arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
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;
}
//-------------------
int h, w;
const int MX = 2000 + 5;
bool blocked[MX][MX];
int value[MX][MX];
int main() {
cin >> h >> w;
FOR(i, 1, h) {
string s;
cin >> s;
FOR(j, 1, w + 1) {
if (j == w + 1)
blocked[i][j] = true;
else if (s[j - 1] == '#') {
blocked[i][j] = true;
}
}
}
FOR(j, 1, w) blocked[h + 1][j] = true;
FOR(i, 1, h) {
bool *b_now = blocked[i];
int *v_now = value[i];
int r = 1, l = 1;
while (r <= w + 1) {
if (b_now[r] == true) {
int cnt = r - l;
FOR(j, l, r - 1) v_now[j] += cnt;
r += 1;
l = r;
} else {
r += 1;
}
}
}
FOR(i, 1, w) {
int u = 1, d = 1;
while (d <= h + 1) {
if (blocked[d][i] == true) {
int cnt = d - u;
FOR(j, u, d - 1) value[j][i] += cnt - 1;
d += 1;
u = d;
} else {
d += 1;
}
}
}
int ans = 0;
FOR(i, 1, h) { ans = max(*max_element(value[i], value[i] + w), ans); }
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORR(x, arr) for (auto &x : arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
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;
}
//-------------------
int h, w;
const int MX = 2000 + 5;
bool blocked[MX][MX];
int value[MX][MX];
int main() {
cin >> h >> w;
FOR(i, 1, h) {
string s;
cin >> s;
FOR(j, 1, w + 1) {
if (j == w + 1)
blocked[i][j] = true;
else if (s[j - 1] == '#') {
blocked[i][j] = true;
}
}
}
FOR(j, 1, w) blocked[h + 1][j] = true;
FOR(i, 1, h) {
bool *b_now = blocked[i];
int *v_now = value[i];
int r = 1, l = 1;
while (r <= w + 1) {
if (b_now[r] == true) {
int cnt = r - l;
FOR(j, l, r - 1) v_now[j] += cnt;
r += 1;
l = r;
} else {
r += 1;
}
}
}
FOR(i, 1, w) {
int u = 1, d = 1;
while (d <= h + 1) {
if (blocked[d][i] == true) {
int cnt = d - u;
FOR(j, u, d - 1) value[j][i] += cnt - 1;
d += 1;
u = d;
} else {
d += 1;
}
}
}
int ans = 0;
FOR(i, 1, h) { ans = max(*max_element(value[i], value[i] + w + 1), ans); }
cout << ans << endl;
return 0;
}
| [
"assignment.change"
] | 828,292 | 828,293 | u297590902 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
int H, W;
int h1[2009], h2[2009];
int main() {
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; i++)
cin >> S[i];
int ans = 1;
for (int i = 0; i < W; i++) {
h1[i] = -1;
h2[i] = H;
}
for (int i = 0; i < H; i++) {
//ๆๅใฏใในๅคใซ้ๅฎณ็ฉใใใใจใใ
int w1 = -1, w2 = W;
for (int c = 0; c < W; c++) {
if (S[i][c] == '#') {
w2 = c;
break;
}
}
for (int j = 0; j < W; j++) {
if (i == 0) {
for (int b = 0; b < H; b++) {
if (S[b][j] = '#') {
h2[j] = b;
break;
}
}
}
//้ๅฎณ็ฉใ ใฃใใ็ซฏใๆดๆฐใใฆไธญๆญ
if (S[i][j] == '#') {
w1 = j;
h1[j] = i;
continue;
}
if (j >= w2) {
w2 = W;
for (int c = j + 1; c < W; c++) {
if (S[i][c] == '#') {
w2 = c;
break;
}
}
}
if (i >= h2[j]) {
h2[j] = H;
for (int b = i + 1; b < H; b++) {
if (S[b][j] == '#') {
h2[j] = b;
break;
}
}
}
ans = max(ans, h2[j] - h1[j] + w2 - w1 - 2);
// if(ans==4){cout << i << " " << j << " " << h2[j] << " " << h1[j] << " "
// << w2 << " " << w1 << endl; return 0;} if(ans==H+W-1){cout << ans <<
// endl; return 0;}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int H, W;
int h1[2009], h2[2009];
int main() {
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; i++)
cin >> S[i];
int ans = 1;
for (int i = 0; i < W; i++) {
h1[i] = -1;
h2[i] = H;
}
for (int i = 0; i < H; i++) {
//ๆๅใฏใในๅคใซ้ๅฎณ็ฉใใใใจใใ
int w1 = -1, w2 = W;
for (int c = 0; c < W; c++) {
if (S[i][c] == '#') {
w2 = c;
break;
}
}
for (int j = 0; j < W; j++) {
if (i == 0) {
for (int b = 0; b < H; b++) {
if (S[b][j] == '#') {
h2[j] = b;
break;
}
}
}
//้ๅฎณ็ฉใ ใฃใใ็ซฏใๆดๆฐใใฆไธญๆญ
if (S[i][j] == '#') {
w1 = j;
h1[j] = i;
continue;
}
if (j >= w2) {
w2 = W;
for (int c = j + 1; c < W; c++) {
if (S[i][c] == '#') {
w2 = c;
break;
}
}
}
if (i >= h2[j]) {
h2[j] = H;
for (int b = i + 1; b < H; b++) {
if (S[b][j] == '#') {
h2[j] = b;
break;
}
}
}
ans = max(ans, h2[j] - h1[j] + w2 - w1 - 3);
// if(ans==4){cout << i << " " << j << " " << h2[j] << " " << h1[j] << " "
// << w2 << " " << w1 << endl; return 0;} if(ans==H+W-1){cout << ans <<
// endl; return 0;}
}
}
cout << ans << endl;
} | [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo",
"literal.number.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 828,297 | 828,298 | u302870145 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int h, w;
string s[2010];
int mxh[2010][2010], mxw[2010][2010];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> h >> w;
for (int i = 0; i < h; i++) {
cin >> s[i];
}
int nw;
int be;
for (int i = 0; i < h; i++) {
nw = 0;
be = 0;
for (int j = 0; j < w; j++) {
if (s[i][j] == '.')
nw++;
if (s[i][j] == '#') {
mxh[i][be] = nw;
mxh[i][j] = -nw;
be = j + 1;
nw = 0;
}
}
mxh[i][be] = nw;
}
for (int i = 0; i < w; i++) {
nw = 0;
be = 0;
for (int j = 0; j < h; j++) {
if (s[j][i] == '.')
nw++;
if (s[j][i] == '#') {
mxw[be][i] = nw;
mxw[j][i] = -nw;
be = j + 1;
nw = 0;
}
}
mxw[be][i] = nw;
}
int ans = 0;
for (int i = 1; i < h; i++) {
for (int j = 0; j < w; j++) {
mxh[i][j] += mxh[i][j - 1];
}
}
for (int i = 1; i < w; i++) {
for (int j = 0; j < h; j++) {
mxw[j][i] += mxw[j - 1][i];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, mxh[i][j] + mxw[i][j] - 1);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int h, w;
string s[2010];
int mxh[2010][2010], mxw[2010][2010];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> h >> w;
for (int i = 0; i < h; i++) {
cin >> s[i];
}
int nw;
int be;
for (int i = 0; i < h; i++) {
nw = 0;
be = 0;
for (int j = 0; j < w; j++) {
if (s[i][j] == '.')
nw++;
if (s[i][j] == '#') {
mxh[i][be] = nw;
mxh[i][j] = -nw;
be = j + 1;
nw = 0;
}
}
mxh[i][be] = nw;
}
for (int i = 0; i < w; i++) {
nw = 0;
be = 0;
for (int j = 0; j < h; j++) {
if (s[j][i] == '.')
nw++;
if (s[j][i] == '#') {
mxw[be][i] = nw;
mxw[j][i] = -nw;
be = j + 1;
nw = 0;
}
}
mxw[be][i] = nw;
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 1; j < w; j++) {
mxh[i][j] += mxh[i][j - 1];
}
}
for (int i = 0; i < w; i++) {
for (int j = 1; j < h; j++) {
mxw[j][i] += mxw[j - 1][i];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, mxh[i][j] + mxw[i][j] - 1);
}
}
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 828,307 | 828,308 | u247996218 | cpp |
p03014 | #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;
}
| [
"identifier.change",
"call.arguments.change"
] | 828,309 | 828,310 | u330661451 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;
// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }
ll comb(int n, int r) {
if (!po[n]) {
po[0] = 1;
FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
}
return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
while (a % b != 0) {
ll tmp = a;
a = b;
b = tmp % b;
}
return b;
}
int H, W;
string ss[2001];
int hs[2001], ws[2001];
map<int, queue<int>> hg;
map<int, vector<int>> wg;
int main() {
scanf("%d %d", &H, &W);
rep(i, H) cin >> ss[i];
rep(i, H) {
rep(j, W) {
string s = ss[i];
char c = s[j];
if (c == '#') {
hg[i].push(j);
wg[j].push_back(i);
}
}
}
int max_lamp = 0;
rep(i, H) {
int bef_w = 0;
int af_w = W;
rep(j, W) {
if (ss[i][j] == '#')
continue;
if (af_w < j) {
bef_w = af_w + 1;
if (hg[i].empty())
af_w = W;
}
if (!hg[i].empty()) {
if (j < af_w && af_w != W)
break;
int w = hg[i].front();
hg[i].pop();
while (w < j) {
bef_w = w + 1;
if (hg[i].empty()) {
w = W;
break;
} else {
w = hg[i].front();
hg[i].pop();
}
}
af_w = w;
}
int w_lamp = af_w - bef_w;
int bef_h = 0;
int af_h = H;
for (int h : wg[j]) {
if (h < i)
bef_h = h + 1;
else {
af_h = h;
break;
}
}
int h_lamp = af_h - bef_h;
max_lamp = max(max_lamp, w_lamp + h_lamp - 1);
}
}
printf("%d\n", max_lamp);
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;
// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }
ll comb(int n, int r) {
if (!po[n]) {
po[0] = 1;
FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
}
return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
while (a % b != 0) {
ll tmp = a;
a = b;
b = tmp % b;
}
return b;
}
int H, W;
string ss[2001];
int hs[2001], ws[2001];
map<int, queue<int>> hg;
map<int, vector<int>> wg;
int main() {
scanf("%d %d", &H, &W);
rep(i, H) cin >> ss[i];
rep(i, H) {
rep(j, W) {
string s = ss[i];
char c = s[j];
if (c == '#') {
hg[i].push(j);
wg[j].push_back(i);
}
}
}
int max_lamp = 0;
rep(i, H) {
int bef_w = 0;
int af_w = W;
rep(j, W) {
if (ss[i][j] == '#')
continue;
if (af_w < j) {
bef_w = af_w + 1;
if (hg[i].empty())
af_w = W;
}
if (!hg[i].empty()) {
if (!(j < af_w && af_w != W)) {
int w = hg[i].front();
hg[i].pop();
while (w < j) {
bef_w = w + 1;
if (hg[i].empty()) {
w = W;
break;
} else {
w = hg[i].front();
hg[i].pop();
}
}
af_w = w;
}
}
int w_lamp = af_w - bef_w;
int bef_h = 0;
int af_h = H;
for (int h : wg[j]) {
if (h < i)
bef_h = h + 1;
else {
af_h = h;
break;
}
}
int h_lamp = af_h - bef_h;
max_lamp = max(max_lamp, w_lamp + h_lamp - 1);
}
}
printf("%d\n", max_lamp);
}
| [
"control_flow.branch.if.condition.change"
] | 828,320 | 828,321 | u823451365 | cpp |
p03014 | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
char s[2001][2001];
int a[2001][2001] = {0};
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int j;
for (int i = 0; i < n; ++i) {
int num = 0;
for (j = 1; j < m; ++j) {
if (s[i][j - 1] != '#' && s[i][j] == '.') {
num++;
a[i][j] += num;
} else
num = 0;
}
num = 0;
for (j = m - 2; j >= 0; --j) {
if (s[i][j + 1] != '#' && s[i][j] == '.') {
num++;
a[i][j] += num;
} else
num = 0;
}
}
int maxnum = -1;
for (int i = 0; i < m; ++i) {
int num = 0;
for (j = 1; j < n; ++j) {
if (s[j - 1][i] != '#' && s[j][i] == '.') {
num++;
a[j][i] += num;
} else
num = 0;
}
num = 0;
for (j = n - 2; j >= 0; --j) {
if (s[j + 1][i] != '#' && s[j][i] == '.') {
num++;
a[j][i] += num;
} else
num = 0;
// maxnum=max(maxnum,a[j][i]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
if (s[i][j] == '.')
maxnum = max(maxnum, a[j][i] + 1); // cout << a[i][j] << " \n"[j==m-1];
}
printf("%d\n", maxnum);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
char s[2001][2001];
int a[2001][2001] = {0};
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int j;
for (int i = 0; i < n; ++i) {
int num = 0;
for (j = 1; j < m; ++j) {
if (s[i][j - 1] != '#' && s[i][j] == '.') {
num++;
a[i][j] += num;
} else
num = 0;
}
num = 0;
for (j = m - 2; j >= 0; --j) {
if (s[i][j + 1] != '#' && s[i][j] == '.') {
num++;
a[i][j] += num;
} else
num = 0;
}
}
int maxnum = -1;
for (int i = 0; i < m; ++i) {
int num = 0;
for (j = 1; j < n; ++j) {
if (s[j - 1][i] != '#' && s[j][i] == '.') {
num++;
a[j][i] += num;
} else
num = 0;
}
num = 0;
for (j = n - 2; j >= 0; --j) {
if (s[j + 1][i] != '#' && s[j][i] == '.') {
num++;
a[j][i] += num;
} else
num = 0;
// maxnum=max(maxnum,a[j][i]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
if (s[i][j] == '.')
maxnum = max(maxnum, a[i][j] + 1);
}
printf("%d\n", maxnum);
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 828,322 | 828,323 | u812003342 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int H, W;
string tmp;
cin >> H >> W;
vector<vector<int>> obsv;
vector<vector<int>> obsh;
vector<string> grid;
for (int i = 0; i < W; i++) {
obsv.emplace_back(vector<int>({-1}));
}
for (int i = 0; i < H; i++) {
cin >> tmp;
grid.push_back(tmp);
vector<int> tmp2;
tmp2.push_back(-1);
for (int j = 0; j < W; j++) {
if (tmp[j] == '#') {
obsv[j].push_back(i);
tmp2.push_back(j);
}
}
tmp2.push_back(W);
obsh.emplace_back(tmp2);
}
for (int i = 0; i < W; i++) {
obsv[i].push_back(H);
}
int maximum = -1;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int lbh =
lower_bound(obsh[i].begin(), obsh[i].end(), i) - obsh[i].begin();
int lbv =
lower_bound(obsv[j].begin(), obsv[j].end(), j) - obsv[j].begin();
int fh = obsh[i][lbh] - obsh[i][lbh - 1] - 1;
int fv = obsv[j][lbv] - obsv[j][lbv - 1] - 1;
if (grid[i][j] != '#') {
maximum = max(maximum, fh + fv - 1);
}
}
}
cout << maximum << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int H, W;
string tmp;
cin >> H >> W;
vector<vector<int>> obsv;
vector<vector<int>> obsh;
vector<string> grid;
for (int i = 0; i < W; i++) {
obsv.emplace_back(vector<int>({-1}));
}
for (int i = 0; i < H; i++) {
cin >> tmp;
grid.push_back(tmp);
vector<int> tmp2;
tmp2.push_back(-1);
for (int j = 0; j < W; j++) {
if (tmp[j] == '#') {
obsv[j].push_back(i);
tmp2.push_back(j);
}
}
tmp2.push_back(W);
obsh.emplace_back(tmp2);
}
for (int i = 0; i < W; i++) {
obsv[i].push_back(H);
}
int maximum = -1;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int lbh =
lower_bound(obsh[i].begin(), obsh[i].end(), j) - obsh[i].begin();
int lbv =
lower_bound(obsv[j].begin(), obsv[j].end(), i) - obsv[j].begin();
int fh = obsh[i][lbh] - obsh[i][lbh - 1] - 1;
int fv = obsv[j][lbv] - obsv[j][lbv - 1] - 1;
if (grid[i][j] != '#') {
maximum = max(maximum, fh + fv - 1);
}
}
}
cout << maximum << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 828,326 | 828,327 | u816580121 | cpp |
p03014 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;
typedef long long ll;
ll a, b, k, n, m, sum, h, w;
const ll maxn = 100005;
const ll mod = 1e9 + 7;
ll num[maxn];
char g[2005][2005];
ll l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];
string s;
int main() {
IOS while (cin >> h >> w) {
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
memset(u, 0, sizeof(u));
memset(d, 0, sizeof(d));
rep1(i, h) rep1(j, w) cin >> g[i][j];
ll now = 0;
rep1(i, h) {
now = 0;
rep1(j, w) {
if (g[i][j] == '#')
now = j;
else {
l[i][j] = now;
}
}
}
rep1(i, w) {
now = 0;
rep1(j, h) {
if (g[j][i] == '#')
now = j;
else {
u[j][i] = now;
}
}
}
for (int i = h; i > 0; i--) {
now = w + 1;
for (int j = w; j > 0; j--) {
if (g[i][j] == '#')
now = j;
else {
r[i][j] = now;
}
}
}
for (int i = w; i > 0; i--) {
now = h + 1;
for (int j = h; j > 0; j--) {
if (g[j][i] == '#')
now = i;
else {
d[j][i] = now;
}
}
}
ll ans = 0;
rep1(i, h) {
rep1(j, w) {
if (g[i][j] == '.') {
ans = max(ans, r[i][j] - l[i][j] + d[i][j] - u[i][j] - 2);
// cout<<ans<<" "<<i<<" "<<j<<" "<<l[i][j]<<" "<<r[i][j]<<"
// "<<u[i][j]<<" "<<d[i][j]<<"\n";
}
}
}
cout << ans - 1 << "\n";
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;
typedef long long ll;
ll a, b, k, n, m, sum, h, w;
const ll maxn = 100005;
const ll mod = 1e9 + 7;
ll num[maxn];
char g[2005][2005];
ll l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];
string s;
int main() {
// IOS
while (cin >> h >> w) {
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
memset(u, 0, sizeof(u));
memset(d, 0, sizeof(d));
rep1(i, h) rep1(j, w) cin >> g[i][j];
ll now = 0;
rep1(i, h) {
now = 0;
rep1(j, w) {
if (g[i][j] == '#')
now = j;
else {
l[i][j] = now;
}
}
}
rep1(i, w) {
now = 0;
rep1(j, h) {
if (g[j][i] == '#')
now = j;
else {
u[j][i] = now;
}
}
}
for (int i = h; i > 0; i--) {
now = w + 1;
for (int j = w; j > 0; j--) {
if (g[i][j] == '#')
now = j;
else {
r[i][j] = now;
}
}
}
for (int i = w; i > 0; i--) {
now = h + 1;
for (int j = h; j > 0; j--) {
if (g[j][i] == '#')
now = j;
else {
d[j][i] = now;
}
}
}
ll ans = 0;
rep1(i, h) {
rep1(j, w) {
if (g[i][j] == '.') {
ans = max(ans, r[i][j] - l[i][j] + d[i][j] - u[i][j] - 2);
// cout<<ans<<" "<<i<<" "<<j<<" "<<l[i][j]<<" "<<r[i][j]<<"
// "<<u[i][j]<<" "<<d[i][j]<<"\n";
}
}
}
cout << ans - 1 << "\n";
}
}
| [
"assignment.value.change",
"identifier.change"
] | 828,337 | 828,338 | u856205835 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
int(name); \
scanf("%d", &(name))
#define GI2(name1, name2) \
int(name1), (name2); \
scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
int(name1), (name2), (name3); \
scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size) \
vector<int>(name)(size); \
FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
string(name); \
cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
string to_string(string s) { return s; }
template <class T> string to_string(vector<T> v) {
string ret = "{";
FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
if (v.size() > 0) {
ret += to_string(v.back());
}
ret += "}";
return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head head, Tail... tail) {
cout << to_string(head);
print(tail...);
}
int main() {
GI2(H, W);
vector<string> S(H);
vector<int> yoko(H * W), tate(H * W);
FOR(i, H) cin >> S[i];
FOR(i, H) {
int now_count = 0;
FOR(j, W) {
if (S[i][j] == '.') {
now_count++;
} else {
for (int x = j - now_count; x < j; ++x) {
yoko[i * W + x] = now_count;
}
now_count = 0;
}
}
if (now_count > 0) {
for (int x = W - now_count; x < W; ++x) {
yoko[i * W + x] = now_count;
}
}
}
FOR(j, W) {
int now_count = 0;
FOR(i, H) {
if (S[i][j] == '.') {
now_count++;
} else {
for (int y = i - now_count; y < i; ++y) {
tate[y * W + j] = now_count;
}
now_count = 0;
}
}
if (now_count > 0) {
for (int y = H - now_count; y < W; ++y) {
tate[y * W + j] = now_count;
}
}
}
int ans = 0;
FOR(i, H) {
FOR(j, W) {
ans = max(ans, yoko[i * W + j] + tate[i * W + j] -
(yoko[i * W + j] > 0 && tate[i * W + j] ? 1 : 0));
}
}
print(ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
int(name); \
scanf("%d", &(name))
#define GI2(name1, name2) \
int(name1), (name2); \
scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
int(name1), (name2), (name3); \
scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size) \
vector<int>(name)(size); \
FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
string(name); \
cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
string to_string(string s) { return s; }
template <class T> string to_string(vector<T> v) {
string ret = "{";
FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
if (v.size() > 0) {
ret += to_string(v.back());
}
ret += "}";
return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head head, Tail... tail) {
cout << to_string(head);
print(tail...);
}
int main() {
GI2(H, W);
vector<string> S(H);
vector<int> yoko(H * W), tate(H * W);
FOR(i, H) cin >> S[i];
FOR(i, H) {
int now_count = 0;
FOR(j, W) {
if (S[i][j] == '.') {
now_count++;
} else {
for (int x = j - now_count; x < j; ++x) {
yoko[i * W + x] = now_count;
}
now_count = 0;
}
}
if (now_count > 0) {
for (int x = W - now_count; x < W; ++x) {
yoko[i * W + x] = now_count;
}
}
}
FOR(j, W) {
int now_count = 0;
FOR(i, H) {
if (S[i][j] == '.') {
now_count++;
} else {
for (int y = i - now_count; y < i; ++y) {
tate[y * W + j] = now_count;
}
now_count = 0;
}
}
if (now_count > 0) {
for (int y = H - now_count; y < H; ++y) {
tate[y * W + j] = now_count;
}
}
}
int ans = 0;
FOR(i, H) {
FOR(j, W) {
ans = max(ans, yoko[i * W + j] + tate[i * W + j] -
(yoko[i * W + j] > 0 && tate[i * W + j] ? 1 : 0));
}
}
print(ans);
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 828,339 | 828,340 | u656771711 | cpp |
p03014 | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define DEBUG_MAT(v) \
cerr << #v << endl; \
for (int i = 0; i < v.size(); i++) { \
for (int j = 0; j < v[i].size(); j++) { \
cerr << v[i][j] << " "; \
} \
cerr << endl; \
}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
// #define endl '\n'
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w));
vii r(h, vi(w));
vii u(h, vi(w));
vii d(h, vi(w));
rep(i, h) {
int k = -1;
rep(j, w) {
if (s[i][j] == '#')
k = j;
l[i][j] = k;
}
}
rep(i, h) {
int k = w;
rrep(j, w) {
if (s[i][j] == '#')
k = j;
r[i][j] = k;
}
}
rep(j, w) {
int k = -1;
rep(i, h) {
if (s[i][j] == '#')
k = j;
u[i][j] = k;
}
}
rep(j, w) {
int k = h;
rrep(i, h) {
if (s[i][j] == '#')
k = j;
d[i][j] = k;
}
}
int ans = 0;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '#')
continue;
int temp = (r[i][j] - 1) - l[i][j];
temp += (d[i][j] - 1) - u[i][j];
temp--;
chmax(ans, temp);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define DEBUG_MAT(v) \
cerr << #v << endl; \
for (int i = 0; i < v.size(); i++) { \
for (int j = 0; j < v[i].size(); j++) { \
cerr << v[i][j] << " "; \
} \
cerr << endl; \
}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
// #define endl '\n'
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w));
vii r(h, vi(w));
vii u(h, vi(w));
vii d(h, vi(w));
rep(i, h) {
int k = -1;
rep(j, w) {
if (s[i][j] == '#')
k = j;
l[i][j] = k;
}
}
rep(i, h) {
int k = w;
rrep(j, w) {
if (s[i][j] == '#')
k = j;
r[i][j] = k;
}
}
rep(j, w) {
int k = -1;
rep(i, h) {
if (s[i][j] == '#')
k = i;
u[i][j] = k;
}
}
rep(j, w) {
int k = h;
rrep(i, h) {
if (s[i][j] == '#')
k = i;
d[i][j] = k;
}
}
int ans = 0;
rep(i, h) {
rep(j, w) {
if (s[i][j] == '#')
continue;
int temp = (r[i][j] - 1) - l[i][j];
temp += (d[i][j] - 1) - u[i][j];
temp--;
chmax(ans, temp);
}
}
cout << ans << endl;
}
| [
"assignment.value.change",
"identifier.change"
] | 828,347 | 828,348 | u579152247 | cpp |
p03014 | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int H, W;
cin >> H >> W;
vector<string> field(H);
for (int i = 0; i < H; i++)
cin >> field[i];
vector<vector<int>> dis_tate(W, vector<int>(0));
vector<vector<int>> dis_yoko(H, vector<int>(0));
vector<vector<int>> tate(W, vector<int>(H, 0));
vector<vector<int>> yoko(H, vector<int>(W, 0));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (field[i][j] == '#') {
dis_tate[j].push_back(i);
dis_yoko[i].push_back(j);
}
}
}
for (int i = 0; i < H; i++) {
if (dis_yoko[i].size() == 0) {
for (int k = 0; k < W; k++)
yoko[i][k] = W - 1;
} else {
int t1 = -1, t2; //ใใใใใใใใt1=0ใใใใใชใใใใใใใใชใ
for (int j = 0; j < dis_yoko[i].size(); j++) {
t2 = dis_yoko[i][j];
for (int k = t1 + 1; k < t2; k++)
yoko[i][k] = t2 - t1 - 2;
t1 = t2;
}
for (int k = dis_yoko[i][dis_yoko[i].size() - 1] + 1; k < W; k++) {
yoko[i][k] = W - dis_yoko[i][dis_yoko[i].size() - 1] - 2;
//ใใใฎๆทปๅญใใใใใ
}
}
}
for (int i = 0; i < W; i++) {
if (dis_tate[i].size() == 0) {
for (int k = 0; k < H; k++)
tate[i][k] = H - 1;
} else {
int t1 = -1, t2; //ใใใใใใใใt1=0ใใใใใชใใใใใใใใชใ
for (int j = 0; j < dis_tate[i].size(); j++) {
t2 = dis_tate[i][j];
for (int k = t1 + 1; k < t2; k++)
tate[i][k] = t2 - t1 - 2;
t1 = t2;
}
for (int k = dis_tate[i][dis_tate[i].size() - 1] + 1; k < H; k++) {
tate[i][k] = W - dis_tate[i][dis_tate[i].size() - 1] - 2;
//ใใใฎๆทปๅญใใใใใ
}
}
}
int ans = 0;
// cout<<"tate"<<endl;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
// cout<<tate[j][i];
int tmp = tate[j][i] + yoko[i][j];
ans = max(ans, tmp);
}
// cout<<endl;
}
// cout<<"yoko"<<endl;
// for(int i=0;i<W;i++){
// for(int j=0;j<H;j++){
// cout<<yoko[i][j];
// }
// cout<<endl;
//}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int H, W;
cin >> H >> W;
vector<string> field(H);
for (int i = 0; i < H; i++)
cin >> field[i];
vector<vector<int>> dis_tate(W, vector<int>(0));
vector<vector<int>> dis_yoko(H, vector<int>(0));
vector<vector<int>> tate(W, vector<int>(H, 0));
vector<vector<int>> yoko(H, vector<int>(W, 0));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (field[i][j] == '#') {
dis_tate[j].push_back(i);
dis_yoko[i].push_back(j);
}
}
}
for (int i = 0; i < H; i++) {
if (dis_yoko[i].size() == 0) {
for (int k = 0; k < W; k++)
yoko[i][k] = W - 1;
} else {
int t1 = -1, t2; //ใใใใใใใใt1=0ใใใใใชใใใใใใใใชใ
for (int j = 0; j < dis_yoko[i].size(); j++) {
t2 = dis_yoko[i][j];
for (int k = t1 + 1; k < t2; k++)
yoko[i][k] = t2 - t1 - 2;
t1 = t2;
}
for (int k = dis_yoko[i][dis_yoko[i].size() - 1] + 1; k < W; k++) {
yoko[i][k] = W - dis_yoko[i][dis_yoko[i].size() - 1] - 2;
//ใใใฎๆทปๅญใใใใใ
}
}
}
for (int i = 0; i < W; i++) {
if (dis_tate[i].size() == 0) {
for (int k = 0; k < H; k++)
tate[i][k] = H - 1;
} else {
int t1 = -1, t2; //ใใใใใใใใt1=0ใใใใใชใใใใใใใใชใ
for (int j = 0; j < dis_tate[i].size(); j++) {
t2 = dis_tate[i][j];
for (int k = t1 + 1; k < t2; k++)
tate[i][k] = t2 - t1 - 2;
t1 = t2;
}
for (int k = dis_tate[i][dis_tate[i].size() - 1] + 1; k < H; k++) {
tate[i][k] = H - dis_tate[i][dis_tate[i].size() - 1] - 2;
//ใใใฎๆทปๅญใใใใใ
}
}
}
int ans = 0;
// cout<<"tate"<<endl;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
// cout<<tate[j][i];
int tmp = tate[j][i] + yoko[i][j];
ans = max(ans, tmp);
}
// cout<<endl;
}
cout << ans + 1 << endl;
} | [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 829,032 | 829,033 | u176979814 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int, int>;
ll mod = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
const long long INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int l[2100][2100], r[2100][2100], up[2100][2100], down[2100][2100];
int main() {
int h, w, ans = 0;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; ++i) {
cin >> s[i];
}
for (int i = 0; i < h; ++i) {
int tmp = 0;
for (int j = 0; j < w; ++j) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
l[i][j] = tmp;
}
}
for (int i = 0; i < h; ++i) {
int tmp = 0;
for (int j = w - 1; j >= 0; --j) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
r[i][j] = tmp;
}
}
for (int j = 0; j < w; ++j) {
int tmp = 0;
for (int i = 0; i < h; ++i) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
up[i][j] = tmp;
}
}
for (int j = 0; j < h; ++j) {
int tmp = 0;
for (int i = h - 1; i >= 0; --i) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
down[i][j] = tmp;
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (s[i][j] == '#')
continue;
ans = max(ans, l[i][j] + r[i][j] + down[i][j] + up[i][j] - 3);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int, int>;
ll mod = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
void chmin(long long &a, long long b) {
if (a > b)
a = b;
}
const long long INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int l[2100][2100], r[2100][2100], up[2100][2100], down[2100][2100];
int main() {
int h, w, ans = 0;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; ++i) {
cin >> s[i];
}
for (int i = 0; i < h; ++i) {
int tmp = 0;
for (int j = 0; j < w; ++j) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
l[i][j] = tmp;
}
}
for (int i = 0; i < h; ++i) {
int tmp = 0;
for (int j = w - 1; j >= 0; --j) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
r[i][j] = tmp;
}
}
for (int j = 0; j < w; ++j) {
int tmp = 0;
for (int i = 0; i < h; ++i) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
up[i][j] = tmp;
}
}
for (int j = 0; j < w; ++j) {
int tmp = 0;
for (int i = h - 1; i >= 0; --i) {
if (s[i][j] == '#')
tmp = 0;
else
tmp++;
down[i][j] = tmp;
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (s[i][j] == '#')
continue;
ans = max(ans, l[i][j] + r[i][j] + down[i][j] + up[i][j] - 3);
}
}
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 829,036 | 829,037 | u542670845 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v) \
sort(v.begin(), v.end()); \
reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX
struct cell {
int up;
int down;
int left;
int right;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w;
cin >> h >> w;
vector<string> m(h);
rep(i, h) { cin >> m[i]; }
vector<vector<cell>> a(h, vector<cell>(w));
rep(x, w) {
REP(y, h) {
if (m[y - 1][x] == '.') {
a[y][x].up = a[y - 1][x].up + 1;
} else {
a[y][x].up = 0;
}
}
}
rep(y, h) {
REP(x, w) {
if (m[y][x - 1] == '.') {
a[y][x].left = a[y][x - 1].left + 1;
} else {
a[y][x].left = 0;
}
}
}
for (int x = w - 1; x >= 0; x--) {
for (int y = h - 2; y >= 0; y--) {
if (m[y + 1][x] == '.') {
a[y][x].down = a[y + 1][x].down + 1;
} else {
a[y][x].down = 0;
}
}
}
for (int y = h - 1; y >= 0; y--) {
for (int x = w - 2; x >= 0; x--) {
if (m[y][x + 1] == '.') {
a[y][x].right = a[y][x + 1].right + 1;
} else {
a[y][x].right = 0;
}
}
}
int ans = 0;
rep(y, h) {
REP(x, w) {
if (m[y][x] == '.') {
chmax(ans,
a[y][x].up + a[y][x].down + a[y][x].left + a[y][x].right + 1);
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v) \
sort(v.begin(), v.end()); \
reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX
struct cell {
int up;
int down;
int left;
int right;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w;
cin >> h >> w;
vector<string> m(h);
rep(i, h) { cin >> m[i]; }
vector<vector<cell>> a(h, vector<cell>(w));
rep(x, w) {
REP(y, h) {
if (m[y - 1][x] == '.') {
a[y][x].up = a[y - 1][x].up + 1;
} else {
a[y][x].up = 0;
}
}
}
rep(y, h) {
REP(x, w) {
if (m[y][x - 1] == '.') {
a[y][x].left = a[y][x - 1].left + 1;
} else {
a[y][x].left = 0;
}
}
}
for (int x = w - 1; x >= 0; x--) {
for (int y = h - 2; y >= 0; y--) {
if (m[y + 1][x] == '.') {
a[y][x].down = a[y + 1][x].down + 1;
} else {
a[y][x].down = 0;
}
}
}
for (int y = h - 1; y >= 0; y--) {
for (int x = w - 2; x >= 0; x--) {
if (m[y][x + 1] == '.') {
a[y][x].right = a[y][x + 1].right + 1;
} else {
a[y][x].right = 0;
}
}
}
int ans = 0;
rep(y, h) {
rep(x, w) {
if (m[y][x] == '.') {
chmax(ans,
a[y][x].up + a[y][x].down + a[y][x].left + a[y][x].right + 1);
}
}
}
cout << ans << endl;
return 0;
}
| [
"identifier.change"
] | 829,038 | 829,039 | u324825702 | cpp |
p03014 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
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;
}
vector<vector<int>> obs_row;
vector<vector<int>> obs_col;
vector<string> grid;
int solve(const int H, const int W) {
int maximum = 0;
for (int h = 1; h <= H; h++) {
for (int w = 1; w <= W; w++) {
if (grid[h - 1][w - 1] == '#')
continue;
auto row = obs_row[h];
auto col = obs_col[w];
int left = *(upper_bound(row.begin(), row.end(), w) -
1); // the position of the nearest obstracle in left
int right = *(lower_bound(row.begin(), row.end(), w)); // in right
int up = *(upper_bound(col.begin(), col.end(), h) - 1); // in up
int down = *(lower_bound(col.begin(), col.end(), h)); // in down
int res = (right - left - 1) + (down - up - 1) - 1;
chmax(maximum, res);
}
}
return maximum;
}
int main(void) {
int H, W;
cin >> H >> W;
grid.resize(H);
obs_row.resize(H + 1);
obs_col.resize(W + 1);
for (int i = 1; i <= W; i++) {
obs_col[i].push_back(0);
}
for (int i = 1; i <= H; i++) {
string S;
cin >> S;
grid[i - 1] = "#" + S;
obs_row[i].push_back(0);
for (int j = 1; j <= W; j++) {
if (S[j - 1] == '#') {
obs_row[i].push_back(j);
obs_col[j].push_back(i);
}
}
obs_row[i].push_back(W + 1);
}
for (int i = 1; i <= W; i++) {
obs_col[i].push_back(H + 1);
}
// cout << "obs_row: " << endl;
// for (int i = 0; i < (int) obs_row.size(); i++) {
// for (int j = 0; j < (int) obs_row[i].size(); j++) {
// cout << obs_row[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// cout << "obs_col: " << endl;
// for (int i = 0; i < (int) obs_col.size(); i++) {
// for (int j = 0; j < (int) obs_col[i].size(); j++) {
// cout << obs_col[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
cout << solve(H, W) << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
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;
}
vector<vector<int>> obs_row;
vector<vector<int>> obs_col;
vector<string> grid;
int solve(const int H, const int W) {
int maximum = 0;
for (int h = 1; h <= H; h++) {
for (int w = 1; w <= W; w++) {
if (grid[h - 1][w - 1] == '#')
continue;
auto row = obs_row[h];
auto col = obs_col[w];
int left = *(upper_bound(row.begin(), row.end(), w) -
1); // the position of the nearest obstracle in left
int right = *(lower_bound(row.begin(), row.end(), w)); // in right
int up = *(upper_bound(col.begin(), col.end(), h) - 1); // in up
int down = *(lower_bound(col.begin(), col.end(), h)); // in down
// printf("(%d, %d) left: %d, right: %d, up: %d, down: %d\n", w, h, left,
// right, up, down);
int res = (right - left - 1) + (down - up - 1) - 1;
chmax(maximum, res);
}
}
return maximum;
}
int main(void) {
int H, W;
cin >> H >> W;
grid.resize(H);
obs_row.resize(H + 1);
obs_col.resize(W + 1);
for (int i = 1; i <= W; i++) {
obs_col[i].push_back(0);
}
for (int i = 1; i <= H; i++) {
string S;
cin >> S;
grid[i - 1] = S;
obs_row[i].push_back(0);
for (int j = 1; j <= W; j++) {
if (S[j - 1] == '#') {
obs_row[i].push_back(j);
obs_col[j].push_back(i);
}
}
obs_row[i].push_back(W + 1);
}
for (int i = 1; i <= W; i++) {
obs_col[i].push_back(H + 1);
}
// cout << "obs_row: " << endl;
// for (int i = 0; i < (int) obs_row.size(); i++) {
// for (int j = 0; j < (int) obs_row[i].size(); j++) {
// cout << obs_row[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// cout << "obs_col: " << endl;
// for (int i = 0; i < (int) obs_col.size(); i++) {
// for (int j = 0; j < (int) obs_col[i].size(); j++) {
// cout << obs_col[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
cout << solve(H, W) << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 829,044 | 829,045 | u644332191 | cpp |
p03014 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; --i)
using ll = long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;
int l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];
int main() {
int h, w;
cin >> h >> w;
int count = 0;
vector<string> maze(h);
repp(i, 0, h) cin >> maze[i];
repp(i, 0, h) {
repm(j, w - 1, -1) {
if (maze[i][j] == '#')
count = 0;
else
count++;
r[i][j] = count;
}
count = 0;
repp(j, 0, w) {
if (maze[i][j] == '#')
count = 0;
else
count++;
l[i][j] = count;
}
}
repp(j, 0, w) {
count = 0;
repm(i, h - 1, -1) {
if (maze[i][j] == '#')
count = 0;
else
count++;
d[i][j] = count;
}
count = 0;
repp(i, 0, h) {
if (maze[i][j] == '#')
count = 0; //#ใฏๆฐใใใใใใใใงใชใปใใ
else
count++;
u[i][j] = count;
}
}
int maxv = 0;
repp(i, 0, h) repp(j, 0, w) {
if (maze[i][j] == '#')
continue;
maxv = max(maxv, l[i][j] + r[i][j] + u[i][j] + d[i][j] -
3); //ใฉใณใใ็ฝฎใใใในใฏ4ๅๆฐใใใใฆใใใฎใง-3
}
cout << maxv << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; --i)
using ll = long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;
int l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];
int main() {
int h, w;
cin >> h >> w;
int count = 0;
vector<string> maze(h);
repp(i, 0, h) cin >> maze[i];
repp(i, 0, h) {
count = 0;
repm(j, w - 1, -1) {
if (maze[i][j] == '#')
count = 0;
else
count++;
r[i][j] = count;
}
count = 0;
repp(j, 0, w) {
if (maze[i][j] == '#')
count = 0;
else
count++;
l[i][j] = count;
}
}
repp(j, 0, w) {
count = 0;
repm(i, h - 1, -1) {
if (maze[i][j] == '#')
count = 0;
else
count++;
d[i][j] = count;
}
count = 0;
repp(i, 0, h) {
if (maze[i][j] == '#')
count = 0; //#ใฏๆฐใใใใใใใใงใชใปใใ
else
count++;
u[i][j] = count;
}
}
int maxv = 0;
repp(i, 0, h) repp(j, 0, w) {
if (maze[i][j] == '#')
continue;
maxv = max(maxv, l[i][j] + r[i][j] + u[i][j] + d[i][j] -
3); //ใฉใณใใ็ฝฎใใใในใฏ4ๅๆฐใใใใฆใใใฎใง-3
}
cout << maxv << endl;
return 0;
} | [
"assignment.add"
] | 829,048 | 829,049 | u698883164 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
signed main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
vii A(H, vi(W));
rep(i, 0, H) {
cin >> S[i];
int count = 0;
rep(j, 0, W) {
if (S[i][j] == '.')
count++;
else {
rep(k, j - count, j) A[i][k] = count;
count = 0;
}
rep(k, W - count, W) A[i][k] = count;
}
}
rep(i, 0, W) {
int count = 0;
rep(j, 0, H) {
if (S[j][i] == '.')
count++;
else {
rep(k, j - count, j) A[j][i] += count;
count = 0;
}
rep(k, H - count, H) A[j][i] += count;
}
}
int ans = 0;
rep(i, 0, H) { rep(j, 0, W) ans = max(ans, A[i][j] - 1); }
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
signed main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
vii A(H, vi(W));
rep(i, 0, H) {
cin >> S[i];
int count = 0;
rep(j, 0, W) {
if (S[i][j] == '.')
count++;
else {
rep(k, j - count, j) A[i][k] = count;
count = 0;
}
}
rep(k, W - count, W) A[i][k] = count;
}
rep(i, 0, W) {
int count = 0;
rep(j, 0, H) {
if (S[j][i] == '.')
count++;
else {
rep(k, j - count, j) A[k][i] += count;
count = 0;
}
}
rep(k, H - count, H) A[k][i] += count;
}
int ans = 0;
rep(i, 0, H) { rep(j, 0, W) ans = max(ans, A[i][j] - 1); }
cout << ans << endl;
}
| [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 829,059 | 829,058 | u347057617 | cpp |
p03014 | /* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define beg begin
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define repA(i, x, y) for (int i = (x); i <= (y); i++)
#define repD(i, x, y) for (int i = (x); i >= (y); i--)
#define all(c) (c).begin(), (c).end()
#define fill(a, val) memset(a, val, sizeof(a))
#define Randomize \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3 * 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int SZ = 101;
const double eps = 1e-9;
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif
#ifndef AaryanS
#define mycout \
if (false) \
cout
#define mycerr \
if (false) \
cerr
#endif
const int M = 2005;
int a[M][M][4], obs[M][M];
// 0 L 1 R 2 U 3 D
void solve() {
int n, m;
cin >> n >> m;
string s[n];
rep(i, n) {
cin >> s[i];
rep(j, m) if (s[i][j] == '#') { obs[i][j] = 1; }
}
rep(i, n) {
int last = -1;
rep(j, m) {
if (obs[i][j]) {
last = j;
}
a[i][j][0] = last;
}
}
rep(i, n) {
int last = m;
repD(j, m - 1, 0) {
if (obs[i][j]) {
last = j;
}
a[i][j][1] = last;
}
}
rep(j, m) {
int last = -1;
rep(i, n) {
if (obs[i][j]) {
last = i;
}
a[i][j][2] = last;
}
}
rep(j, m) {
int last = n;
rep(i, n) {
if (obs[i][j]) {
last = j;
}
a[i][j][3] = last;
}
}
int res = 0;
rep(i, n) {
rep(j, m) {
if (obs[i][j])
continue;
int ans = (j - a[i][j][0]) + (a[i][j][1] - j) + (i - a[i][j][2]) +
(a[i][j][3] - i);
ans -= 3;
res = max(ans, res);
}
}
cout << res;
}
int32_t main(int32_t argc, char *argv[]) {
double t1 = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC = 1, t = 0;
// cin >> TC ;
while (t++ < TC) {
// cout << "Case #" << t << ": " ;
solve();
// cout << endl ;
}
mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
return 0;
} | /* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define beg begin
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define repA(i, x, y) for (int i = (x); i <= (y); i++)
#define repD(i, x, y) for (int i = (x); i >= (y); i--)
#define all(c) (c).begin(), (c).end()
#define fill(a, val) memset(a, val, sizeof(a))
#define Randomize \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3 * 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int SZ = 101;
const double eps = 1e-9;
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif
#ifndef AaryanS
#define mycout \
if (false) \
cout
#define mycerr \
if (false) \
cerr
#endif
const int M = 2005;
int a[M][M][4], obs[M][M];
// 0 L 1 R 2 U 3 D
void solve() {
int n, m;
cin >> n >> m;
string s[n];
rep(i, n) {
cin >> s[i];
rep(j, m) if (s[i][j] == '#') { obs[i][j] = 1; }
}
rep(i, n) {
int last = -1;
rep(j, m) {
if (obs[i][j]) {
last = j;
}
a[i][j][0] = last;
}
}
rep(i, n) {
int last = m;
repD(j, m - 1, 0) {
if (obs[i][j]) {
last = j;
}
a[i][j][1] = last;
}
}
rep(j, m) {
int last = -1;
rep(i, n) {
if (obs[i][j]) {
last = i;
}
a[i][j][2] = last;
}
}
rep(j, m) {
int last = n;
repD(i, n - 1, 0) {
if (obs[i][j]) {
last = i;
}
a[i][j][3] = last;
}
}
int res = 0;
rep(i, n) {
rep(j, m) {
if (obs[i][j])
continue;
int ans = (j - a[i][j][0]) + (a[i][j][1] - j) + (i - a[i][j][2]) +
(a[i][j][3] - i);
ans -= 3;
// rep(k,4)
// cout << a[i][j][k] << " " ;
// cout << endl ;
// cout << i << " " << j << endl ;
res = max(ans, res);
}
}
cout << res;
}
int32_t main(int32_t argc, char *argv[]) {
double t1 = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC = 1, t = 0;
// cin >> TC ;
while (t++ < TC) {
// cout << "Case #" << t << ": " ;
solve();
// cout << endl ;
}
mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
return 0;
} | [
"call.arguments.add",
"assignment.value.change",
"identifier.change"
] | 829,068 | 829,069 | u774189121 | cpp |
p03014 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
/* ใกใใใจ่ใใฆๅฎ่ฃ
ใใฆๅ้กใชใACใงใใๆๅฌใใใ๏ผ๏ผ */
int main(void) {
int h, w;
cin >> h >> w;
vector<string> s;
for (int i = 0; i < h; i++) {
string tmp_s;
cin >> tmp_s;
s.push_back(tmp_s);
}
int L[h][w]; // <-
int R[h][w]; // ->
int U[h][w]; // โ
int D[h][w]; // โ
// ๅๆๅ
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
L[i][j] = 0;
R[i][j] = 0;
U[i][j] = 0;
D[i][j] = 0;
}
}
// L,R
for (int i = 0; i < h; i++) {
if (s[i][0] == '.') {
L[i][0] = 1;
} else {
L[i][0] = 0;
}
if (s[i][w - 1] == '.') {
R[i][w - 1] = 1;
} else {
R[i][w - 1] = 0;
}
}
// U,D
for (int j = 0; j < w; j++) {
if (s[0][j] == '.') {
U[0][j] = 1;
} else {
U[0][j] = 0;
}
if (s[h - 1][j] == '.') {
D[h - 1][j] = 1;
} else {
D[h - 1][j] = 0;
}
}
// ๅๅฆ็
// L
for (int i = 0; i < h; i++) {
for (int j = 1; j < w; j++) {
if (s[i][j] == '.') {
L[i][j] = L[i][j - 1] + 1;
} else {
L[i][j] = 0;
}
}
}
// R
for (int i = 0; i < h; i++) {
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.') {
R[i][j] = R[i][j + 1] + 1;
} else {
R[i][j] = 0;
}
}
}
// U
for (int j = 0; j < w; j++) {
for (int i = 1; i < h; i++) {
if (s[i][j] == '.') {
U[i][j] = U[i - 1][j] + 1;
} else {
U[i][j] = 0;
}
}
}
// D
for (int j = 0; j < w; j++) {
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.') {
D[i][j] = D[i + 1][j] = 1;
} else {
D[i][j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (ans < L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3) {
ans = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
/* ใกใใใจ่ใใฆๅฎ่ฃ
ใใฆๅ้กใชใACใงใใๆๅฌใใใ๏ผ๏ผ */
int main(void) {
int h, w;
cin >> h >> w;
vector<string> s;
for (int i = 0; i < h; i++) {
string tmp_s;
cin >> tmp_s;
s.push_back(tmp_s);
}
int L[h][w]; // <-
int R[h][w]; // ->
int U[h][w]; // โ
int D[h][w]; // โ
// ๅๆๅ
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
L[i][j] = 0;
R[i][j] = 0;
U[i][j] = 0;
D[i][j] = 0;
}
}
// L,R
for (int i = 0; i < h; i++) {
if (s[i][0] == '.') {
L[i][0] = 1;
} else {
L[i][0] = 0;
}
if (s[i][w - 1] == '.') {
R[i][w - 1] = 1;
} else {
R[i][w - 1] = 0;
}
}
// U,D
for (int j = 0; j < w; j++) {
if (s[0][j] == '.') {
U[0][j] = 1;
} else {
U[0][j] = 0;
}
if (s[h - 1][j] == '.') {
D[h - 1][j] = 1;
} else {
D[h - 1][j] = 0;
}
}
// ๅๅฆ็
// L
for (int i = 0; i < h; i++) {
for (int j = 1; j < w; j++) {
if (s[i][j] == '.') {
L[i][j] = L[i][j - 1] + 1;
} else {
L[i][j] = 0;
}
}
}
// R
for (int i = 0; i < h; i++) {
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.') {
R[i][j] = R[i][j + 1] + 1;
} else {
R[i][j] = 0;
}
}
}
// U
for (int j = 0; j < w; j++) {
for (int i = 1; i < h; i++) {
if (s[i][j] == '.') {
U[i][j] = U[i - 1][j] + 1;
} else {
U[i][j] = 0;
}
}
}
// D
for (int j = 0; j < w; j++) {
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.') {
D[i][j] = D[i + 1][j] + 1;
} else {
D[i][j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (ans < L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3) {
ans = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
}
}
}
cout << ans;
return 0;
} | [
"assignment.value.change"
] | 829,072 | 829,073 | u900688325 | cpp |
p03014 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][h - 1] == '.')
l[i][h - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[h - 1][j] == '.')
u[h - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
ll ans = -1;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][w - 1] == '.')
l[i][w - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[h - 1][j] == '.')
u[h - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
int ans = -1;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
/*rep(i, h) {
rep(j, w) {
cout << l[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << r[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << u[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << d[i][j] << " ";
}
cout << endl;
}
cout << endl;
*/} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.variable.change",
"expression.operation.binary.change",
"variable_declaration.type.change"
] | 829,090 | 829,091 | u654115433 | cpp |
p03014 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][h - 1] == '.')
l[i][h - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[h - 1][j] == '.')
u[h - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
ll ans = 0;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][w - 1] == '.')
l[i][w - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[h - 1][j] == '.')
u[h - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
int ans = -1;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
/*rep(i, h) {
rep(j, w) {
cout << l[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << r[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << u[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << d[i][j] << " ";
}
cout << endl;
}
cout << endl;
*/} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.variable.change",
"expression.operation.binary.change",
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.value.change"
] | 829,092 | 829,091 | u654115433 | cpp |
p03014 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][h - 1] == '.')
l[i][h - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[w - 1][j] == '.')
u[w - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
int ans = -1;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) { cin >> s[i]; }
vii l(h, vi(w)), r(h, vi(w)), u(h, vi(w)), d(h, vi(w));
for (int i = 0; i < h; i++) {
if (s[i][0] == '.')
r[i][0] = 1;
for (int j = 1; j < w; j++) {
if (s[i][j] == '.')
r[i][j] = r[i][j - 1] + 1;
else
r[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
if (s[i][w - 1] == '.')
l[i][w - 1] = 1;
for (int j = w - 2; j >= 0; j--) {
if (s[i][j] == '.')
l[i][j] = l[i][j + 1] + 1;
else
l[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[0][j] == '.')
d[0][j] = 1;
for (int i = 1; i < h; i++) {
if (s[i][j] == '.')
d[i][j] = d[i - 1][j] + 1;
else
d[i][j] = 0;
}
}
for (int j = 0; j < w; j++) {
if (s[h - 1][j] == '.')
u[h - 1][j] = 1;
for (int i = h - 2; i >= 0; i--) {
if (s[i][j] == '.')
u[i][j] = u[i + 1][j] + 1;
else
u[i][j] = 0;
}
}
int ans = -1;
rep(i, h) {
rep(j, w) {
int t = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
if (t > ans)
ans = t;
}
}
cout << ans << endl;
/*rep(i, h) {
rep(j, w) {
cout << l[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << r[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << u[i][j] << " ";
}
cout << endl;
}
cout << endl;
rep(i, h) {
rep(j, w) {
cout << d[i][j] << " ";
}
cout << endl;
}
cout << endl;
*/} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.variable.change",
"expression.operation.binary.change"
] | 829,093 | 829,091 | u654115433 | cpp |
p03014 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
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<int>> cnt(h, std::vector<int>(w));
for (int i = 0; i < h; i++) {
// whether the position is already checked
std::vector<int> done(w);
for (int j = 0; j < w; j++) {
//# cannot be lightened
if (s[i][j] == '#')
continue;
// if the cell already checked, it must not be double-counted
if (done[j])
continue;
// length of continuous . sequences
int l = 0;
// whether the right position is . or not
while (j + l < w) {
if (s[i][j] == '#')
break;
l++;
}
// record the number of . between two #s.
for (int k = 0; k < l; k++) {
cnt[i][j + k] += l;
done[j + k] = 1;
}
}
}
// the colum direction
for (int j = 0; j < w; j++) {
// whether the position is already checked
std::vector<int> done(h);
for (int i = 0; i < h; i++) {
//# cannot be lightened
if (s[i][j] == '#')
continue;
// if the cell already checked, it must not be double-counted
if (done[i])
continue;
// length of continuous . sequences
int l = 0;
// whether the lower position is . or not
while (i + l < h) {
if (s[i + l][j] == '#')
break;
++l;
}
// record the number of . between two #s.
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++) {
// the [i][j]the cell is counted doubly-> -1 is needed
ans = std::max(ans, cnt[i][j] - 1);
}
}
std::cout << ans << std::endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
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<int>> cnt(h, std::vector<int>(w));
for (int i = 0; i < h; i++) {
// whether the position is already checked
std::vector<int> done(w);
for (int j = 0; j < w; j++) {
//# cannot be lightened
if (s[i][j] == '#')
continue;
// if the cell already checked, it must not be double-counted
if (done[j])
continue;
// length of continuous . sequences
int l = 0;
// whether the right position is . or not
while (j + l < w) {
if (s[i][j + l] == '#')
break;
l++;
}
// record the number of . between two #s.
for (int k = 0; k < l; k++) {
cnt[i][j + k] += l;
done[j + k] = 1;
}
}
}
// the colum direction
for (int j = 0; j < w; j++) {
// whether the position is already checked
std::vector<int> done(h);
for (int i = 0; i < h; i++) {
//# cannot be lightened
if (s[i][j] == '#')
continue;
// if the cell already checked, it must not be double-counted
if (done[i])
continue;
// length of continuous . sequences
int l = 0;
// whether the lower position is . or not
while (i + l < h) {
if (s[i + l][j] == '#')
break;
++l;
}
// record the number of . between two #s.
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++) {
// the [i][j]the cell is counted doubly-> -1 is needed
ans = std::max(ans, cnt[i][j] - 1);
}
}
std::cout << ans << std::endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 829,103 | 829,104 | u477343425 | cpp |
p03014 | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define INF 1LL << 60
int main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
REP(i, H) cin >> S[i];
vector<vector<int>> R(H, vector<int>(W)), C(H, vector<int>(W));
for (int i = 0; i < H; i++) {
int counter = 0, j_begin = 0;
for (int j = 0; j < W; j++) {
if (S[i][j] == '#') {
for (int t = j_begin; t < j; t++)
R[i][t] = counter;
j_begin = j + 1;
counter = 0;
} else if (j == W - 1 && S[i][j] == '.') {
for (int t = j_begin; t <= j; t++)
R[i][t] = counter + 1;
} else {
counter++;
}
}
}
for (int j = 0; j < W; j++) {
int counter = 0, i_begin = 0;
for (int i = 0; i < H; i++) {
if (S[i][j] == '#') {
for (int t = i_begin; t < i; t++)
C[t][j] = counter;
i_begin = i + 1;
counter = 0;
} else if (i == H - 1 && S[i][j] == '.') {
for (int t = i_begin; t <= i; t++)
C[t][j] = counter + 1;
} else {
counter++;
}
}
}
// for(int i=0; i<H; i++) {
// for(int j=0; j<W; j++) cerr << R[i][j] << " ";
// cerr << endl;
// }
// cerr << endl;
// for(int i=0; i<H; i++) {
// for(int j=0; j<W; j++) cerr << C[i][j] << " ";
// cerr << endl;
// }
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (R[i][j] + C[i][j] > ans)
ans = R[i][j] + C[i][j];
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define INF 1LL << 60
int main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
REP(i, H) cin >> S[i];
vector<vector<int>> R(H, vector<int>(W)), C(H, vector<int>(W));
for (int i = 0; i < H; i++) {
int counter = 0, j_begin = 0;
for (int j = 0; j < W; j++) {
if (S[i][j] == '#') {
for (int t = j_begin; t < j; t++)
R[i][t] = counter;
j_begin = j + 1;
counter = 0;
} else if (j == W - 1 && S[i][j] == '.') {
for (int t = j_begin; t <= j; t++)
R[i][t] = counter + 1;
} else {
counter++;
}
}
}
for (int j = 0; j < W; j++) {
int counter = 0, i_begin = 0;
for (int i = 0; i < H; i++) {
if (S[i][j] == '#') {
for (int t = i_begin; t < i; t++)
C[t][j] = counter;
i_begin = i + 1;
counter = 0;
} else if (i == H - 1 && S[i][j] == '.') {
for (int t = i_begin; t <= i; t++)
C[t][j] = counter + 1;
} else {
counter++;
}
}
}
// for(int i=0; i<H; i++) {
// for(int j=0; j<W; j++) cerr << R[i][j] << " ";
// cerr << endl;
// }
// cerr << endl;
// for(int i=0; i<H; i++) {
// for(int j=0; j<W; j++) cerr << C[i][j] << " ";
// cerr << endl;
// }
int ans = 0;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (R[i][j] + C[i][j] - 1 > ans)
ans = R[i][j] + C[i][j] - 1;
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"assignment.change"
] | 829,107 | 829,108 | u941028483 | cpp |
p03008 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
int main() {
int n;
cin >> n;
vi a(3), b(3);
cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
vi costs;
vi values;
for (int i = 0; i < 3; ++i) {
if (b[i] - a[i] > 0) {
costs.push_back(a[i]);
values.push_back(b[i] - a[i]);
}
}
vl dp(n + 1, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < costs.size(); ++j) {
if (i + costs[j] <= n) {
chmax(dp[i + costs[j]], dp[i] + values[j]);
}
}
}
n += dp[n];
costs.clear();
values.clear();
for (int i = 0; i < 3; ++i) {
if (a[i] - b[i] > 0) {
costs.push_back(b[i]);
values.push_back(a[i] - b[i]);
}
}
dp.resize(n + 1, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < costs.size(); ++j) {
if (i + costs[j] <= n) {
chmax(dp[i + costs[j]], dp[i] + values[j]);
}
}
}
cout << n + dp[n] << "\n";
return 0;
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
int main() {
int n;
cin >> n;
vi a(3), b(3);
cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
vi costs;
vi values;
for (int i = 0; i < 3; ++i) {
if (b[i] - a[i] > 0) {
costs.push_back(a[i]);
values.push_back(b[i] - a[i]);
}
}
vl dp(n + 1, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < costs.size(); ++j) {
if (i + costs[j] <= n) {
chmax(dp[i + costs[j]], dp[i] + values[j]);
}
}
}
n += dp[n];
costs.clear();
values.clear();
for (int i = 0; i < 3; ++i) {
if (a[i] - b[i] > 0) {
costs.push_back(b[i]);
values.push_back(a[i] - b[i]);
}
}
dp.clear();
dp.resize(n + 1, 0);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < costs.size(); ++j) {
if (i + costs[j] <= n) {
chmax(dp[i + costs[j]], dp[i] + values[j]);
}
}
}
cout << n + dp[n] << "\n";
return 0;
} | [
"call.add"
] | 829,124 | 829,125 | u756088996 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLL(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
ll solve(VLL &w, VLL &v, ll W) {
ll n = w.size();
VVLL dp(n + 1, VLL(W + 1, 0));
rep(i, n) {
rep(j, W + 1) {
if (j < w[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max<ll>(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
}
}
}
return dp[n][W];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll r[2][3];
cin >> n;
cin >> r[0][0] >> r[0][1] >> r[0][2];
cin >> r[1][0] >> r[1][1] >> r[1][2];
// step A->B
{
VLL w, v;
rep(i, 3) {
if (r[0][i] < r[1][i]) {
w.push_back(r[0][i]);
v.push_back(r[1][i] - r[0][i]);
}
}
ll add = 0;
if (w.size() > 0)
solve(w, v, n);
if (add > 0)
n += add;
}
// step B -> A
{
VLL w2, v2;
rep(i, 3) {
if (r[1][i] < r[0][i]) {
w2.push_back(r[1][i]);
v2.push_back(r[0][i] - r[1][i]);
}
}
ll add = 0;
;
if (w2.size() > 0) {
add = solve(w2, v2, n);
}
if (add > 0)
n += add;
}
cout << n << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLL(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
ll solve(VLL &w, VLL &v, ll W) {
ll n = w.size();
VVLL dp(n + 1, VLL(W + 1, 0));
rep(i, n) {
rep(j, W + 1) {
if (j < w[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max<ll>(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
}
}
}
return dp[n][W];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
ll r[2][3];
cin >> n;
cin >> r[0][0] >> r[0][1] >> r[0][2];
cin >> r[1][0] >> r[1][1] >> r[1][2];
// step A->B
{
VLL w, v;
rep(i, 3) {
if (r[0][i] < r[1][i]) {
w.push_back(r[0][i]);
v.push_back(r[1][i] - r[0][i]);
}
}
ll add = 0;
if (w.size() > 0)
add = solve(w, v, n);
if (add > 0)
n += add;
}
// step B -> A
{
VLL w2, v2;
rep(i, 3) {
if (r[1][i] < r[0][i]) {
w2.push_back(r[1][i]);
v2.push_back(r[0][i] - r[1][i]);
}
}
ll add = 0;
if (w2.size() > 0) {
add = solve(w2, v2, n);
}
if (add > 0)
n += add;
}
cout << n << endl;
return 0;
}
| [
"variable_declaration.type.change",
"assignment.change"
] | 829,132 | 829,131 | u336011173 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T> void printv(const vector<T> &s) {
for (int i = 0; i < (int)(s.size()); ++i) {
cout << s[i];
if (i == (int)(s.size()) - 1)
cout << endl;
else
cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll ga, sa, ba, gb, sb, bb;
cin >> ga >> sa >> ba >> gb >> sb >> bb;
vvll dp1(4, vll(n + 1, -1));
vll v1 = {ga, sa, ba}, w1 = {gb - ga, sb - sa, bb - ba};
dp1[0][0] = n;
for (ll i = 0; i < 3; ++i) {
for (ll j = 0; j < n + 1; ++j) {
if (dp1[i][j] != -1)
dp1[i + 1][j] = dp1[i][j];
if (j - v1[i] >= 0) {
if (dp1[i + 1][j - v1[i]] != -1)
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i + 1][j - v1[i]] + w1[i]);
}
}
}
ll m = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp1[3][i] != -1)
m = max(m, dp1[3][i]);
}
vll v2 = {gb, sb, bb}, w2 = {ga - gb, sa - sb, ba - bb};
vvll dp2(4, vll(m + 1, -1));
dp2[0][0] = m;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < m + 1; ++j) {
if (dp2[i][j] != -1)
dp2[i + 1][j] = dp2[i][j];
if (j - v2[i] >= 0) {
if (dp2[i + 1][j - v2[i]] != -1)
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i + 1][j - v2[i]] + w2[i]);
}
}
}
ll ma = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp2[3][i] != -1)
ma = max(ma, dp2[3][i]);
}
cout << ma << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T> void printv(const vector<T> &s) {
for (int i = 0; i < (int)(s.size()); ++i) {
cout << s[i];
if (i == (int)(s.size()) - 1)
cout << endl;
else
cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll ga, sa, ba, gb, sb, bb;
cin >> ga >> sa >> ba >> gb >> sb >> bb;
vvll dp1(4, vll(n + 1, -1));
vll v1 = {ga, sa, ba}, w1 = {gb - ga, sb - sa, bb - ba};
dp1[0][0] = n;
for (ll i = 0; i < 3; ++i) {
for (ll j = 0; j < n + 1; ++j) {
if (dp1[i][j] != -1)
dp1[i + 1][j] = dp1[i][j];
if (j - v1[i] >= 0) {
if (dp1[i + 1][j - v1[i]] != -1)
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i + 1][j - v1[i]] + w1[i]);
}
}
}
ll m = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp1[3][i] != -1)
m = max(m, dp1[3][i]);
}
vll v2 = {gb, sb, bb}, w2 = {ga - gb, sa - sb, ba - bb};
vvll dp2(4, vll(m + 1, -1));
dp2[0][0] = m;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < m + 1; ++j) {
if (dp2[i][j] != -1)
dp2[i + 1][j] = dp2[i][j];
if (j - v2[i] >= 0) {
if (dp2[i + 1][j - v2[i]] != -1)
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i + 1][j - v2[i]] + w2[i]);
}
}
}
ll ma = 0;
for (int i = 0; i < m + 1; ++i) {
if (dp2[3][i] != -1)
ma = max(ma, dp2[3][i]);
}
cout << ma << endl;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 829,137 | 829,138 | u334351654 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T> void printv(const vector<T> &s) {
for (int i = 0; i < (int)(s.size()); ++i) {
cout << s[i];
if (i == (int)(s.size()) - 1)
cout << endl;
else
cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll ga, sa, ba, gb, sb, bb;
cin >> ga >> sa >> ba >> gb >> sb >> bb;
vvll dp1(4, vll(n + 1, -1));
vll v1 = {ga, sa, ba}, w1 = {gb - ga, sb - sa, bb - ba};
dp1[0][0] = n;
for (ll i = 0; i < 3; ++i) {
for (ll j = 0; j < n + 1; ++j) {
if (dp1[i][j] != -1)
dp1[i + 1][j] = dp1[i][j];
if (j - v1[i] >= 0) {
if (dp1[i + 1][j - v1[i]] != -1)
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i + 1][j - v1[i]] + w1[i]);
}
}
}
ll m = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp1[3][i] != -1)
m = max(m, dp1[3][i]);
}
vll v2 = {gb, sb, bb}, w2 = {ga - gb, sa - sb, ba - bb};
vvll dp2(4, vll(n + 1, -1));
dp2[0][0] = m;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n + 1; ++j) {
if (dp2[i][j] != -1)
dp2[i + 1][j] = dp2[i][j];
if (j - v2[i] >= 0) {
if (dp2[i + 1][j - v2[i]] != -1)
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i + 1][j - v2[i]] + w2[i]);
}
}
}
ll ma = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp2[3][i] != -1)
ma = max(ma, dp2[3][i]);
}
cout << ma << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T> void printv(const vector<T> &s) {
for (int i = 0; i < (int)(s.size()); ++i) {
cout << s[i];
if (i == (int)(s.size()) - 1)
cout << endl;
else
cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll ga, sa, ba, gb, sb, bb;
cin >> ga >> sa >> ba >> gb >> sb >> bb;
vvll dp1(4, vll(n + 1, -1));
vll v1 = {ga, sa, ba}, w1 = {gb - ga, sb - sa, bb - ba};
dp1[0][0] = n;
for (ll i = 0; i < 3; ++i) {
for (ll j = 0; j < n + 1; ++j) {
if (dp1[i][j] != -1)
dp1[i + 1][j] = dp1[i][j];
if (j - v1[i] >= 0) {
if (dp1[i + 1][j - v1[i]] != -1)
dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i + 1][j - v1[i]] + w1[i]);
}
}
}
ll m = 0;
for (int i = 0; i < n + 1; ++i) {
if (dp1[3][i] != -1)
m = max(m, dp1[3][i]);
}
vll v2 = {gb, sb, bb}, w2 = {ga - gb, sa - sb, ba - bb};
vvll dp2(4, vll(m + 1, -1));
dp2[0][0] = m;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < m + 1; ++j) {
if (dp2[i][j] != -1)
dp2[i + 1][j] = dp2[i][j];
if (j - v2[i] >= 0) {
if (dp2[i + 1][j - v2[i]] != -1)
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i + 1][j - v2[i]] + w2[i]);
}
}
}
ll ma = 0;
for (int i = 0; i < m + 1; ++i) {
if (dp2[3][i] != -1)
ma = max(ma, dp2[3][i]);
}
cout << ma << endl;
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change"
] | 829,139 | 829,138 | u334351654 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;
const ld pi = 3.14159265359;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll) a.size()
ll n, a[3], b[3], dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
REP(i, 3) cin >> a[i];
REP(i, 3) cin >> b[i];
dp[0] = 0;
REP1(i, n) {
dp[i] = i;
REP(j, 3) {
if (i >= a[j])
dp[i] = max(dp[i], dp[i - a[j]] + b[j]);
}
}
n = dp[n];
REP1(i, n) {
dp[i] = i;
REP(j, 3) {
if (i >= b[j])
dp[i] = max(dp[i], dp[i - b[j]] + b[j]);
}
}
cout << dp[n] << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll N = 5000 * 5000 + 5;
const ld pi = 3.14159265359;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll) a.size()
ll n, a[3], b[3], dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
REP(i, 3) cin >> a[i];
REP(i, 3) cin >> b[i];
dp[0] = 0;
REP1(i, n) {
dp[i] = i;
REP(j, 3) {
if (i >= a[j])
dp[i] = max(dp[i], dp[i - a[j]] + b[j]);
}
}
n = dp[n];
REP1(i, n) {
dp[i] = i;
REP(j, 3) {
if (i >= b[j])
dp[i] = max(dp[i], dp[i - b[j]] + a[j]);
}
}
cout << dp[n] << "\n";
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change",
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 829,145 | 829,144 | u028302014 | cpp |
p03008 | #include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool CHMAX(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline void SORT(T &a) { sort(ALL(a)); }
template <typename T> inline void REV(T &a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T &a) {
sort(ALL(a));
a.erase(unique(ALL(a)), a.end());
}
template <typename T> inline T LB(vector<T> &v, T a) {
return *lower_bound(ALL(v), a);
}
template <typename T> inline int LBP(vector<T> &v, T a) {
return lower_bound(ALL(v), a) - v.begin();
}
template <typename T> inline T UB(vector<T> &v, T a) {
return *upper_bound(ALL(v), a);
}
template <typename T> inline int UBP(vector<T> &v, T a) {
return upper_bound(ALL(v), a) - v.begin();
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T = int> 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 V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
#define _DEBUG
int N;
int p[2][3];
int dp[25000010];
void _main() {
cin >> N;
REP(i, 2) REP(j, 3) cin >> p[i][j];
for (int i = 0; i < 3; i++) {
for (int j = p[0][i]; j <= N; j++) {
dp[j] = max(dp[j], dp[j - p[0][i]] + p[1][i] - p[0][i]);
}
}
N += dp[N];
ZERO(dp);
for (int i = 0; i < 3; i++) {
for (int j = p[1][i]; j <= N; j++) {
dp[j] = max(dp[j], dp[j - p[1][i]] + p[0][i] - p[1][i]);
}
}
cout << N + dp[N] << endl;
}
signed main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
_main();
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool CHMAX(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline void SORT(T &a) { sort(ALL(a)); }
template <typename T> inline void REV(T &a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T &a) {
sort(ALL(a));
a.erase(unique(ALL(a)), a.end());
}
template <typename T> inline T LB(vector<T> &v, T a) {
return *lower_bound(ALL(v), a);
}
template <typename T> inline int LBP(vector<T> &v, T a) {
return lower_bound(ALL(v), a) - v.begin();
}
template <typename T> inline T UB(vector<T> &v, T a) {
return *upper_bound(ALL(v), a);
}
template <typename T> inline int UBP(vector<T> &v, T a) {
return upper_bound(ALL(v), a) - v.begin();
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T = int> 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 V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
// #define _DEBUG
int N;
int p[2][3];
int dp[25000010];
void _main() {
cin >> N;
REP(i, 2) REP(j, 3) cin >> p[i][j];
for (int i = 0; i < 3; i++) {
for (int j = p[0][i]; j <= N; j++) {
dp[j] = max(dp[j], dp[j - p[0][i]] + p[1][i] - p[0][i]);
}
}
N += dp[N];
ZERO(dp);
for (int i = 0; i < 3; i++) {
for (int j = p[1][i]; j <= N; j++) {
dp[j] = max(dp[j], dp[j - p[1][i]] + p[0][i] - p[1][i]);
}
}
cout << N + dp[N] << endl;
}
signed main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
_main();
return 0;
} | [] | 829,164 | 829,165 | u141642872 | cpp |
p03008 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
using namespace std;
const ll MAX_N = 5000, MAX_GSB = 5000;
ll N, gsb[3][2], dp[MAX_N * MAX_GSB + 1];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
REP(i, 2) REP(j, 3) cin >> gsb[j][i];
REP(i, 2) {
dp[0] = 0;
FOR(j, 1, MAX_N * MAX_GSB + 1) {
dp[j] = dp[j - 1];
REP(k, 3) {
if (gsb[k][i] <= j) {
dp[j] = max(dp[j], gsb[k][1 - i] + dp[j - gsb[k][i]]);
}
}
}
N = dp[N];
}
cout << N << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
using namespace std;
const ll MAX_N = 5000, MAX_GSB = 5000;
ll N, gsb[3][2], dp[MAX_N * MAX_GSB + 1];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
REP(i, 2) REP(j, 3) cin >> gsb[j][i];
REP(i, 2) {
dp[0] = 0;
FOR(j, 1, MAX_N * MAX_GSB + 1) {
dp[j] = dp[j - 1] + 1;
REP(k, 3) {
if (gsb[k][i] <= j) {
dp[j] = max(dp[j], gsb[k][1 - i] + dp[j - gsb[k][i]]);
}
}
}
N = dp[N];
}
cout << N << endl;
} | [
"assignment.change"
] | 829,174 | 829,175 | u533920479 | cpp |
p03008 | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
const lint mod = 1e9 + 7;
lint solve(int n, lint ga, lint sa, lint ba, lint gb, lint sb, lint bb) {
lint dp[n + 1];
rep(i, n + 1) dp[i] = -1;
dp[0] = 0;
rep(i, n + 1) if (dp[i] >= 0) {
if (i + ga <= n)
dp[i + ga] = max(dp[i + ga], dp[i] + gb);
if (i + sa <= n)
dp[i + sa] = max(dp[i + sa], dp[i] + sb);
if (i + ba <= n)
dp[i + ba] = max(dp[i + ba], dp[i] + bb);
}
lint ret = 0;
rep(i, n + 1) ret = max(ret, dp[i]);
return ret;
}
int main() {
int n;
scanf("%d", &n);
lint g[2], s[2], b[2];
rep(i, 2) scanf("%lld%lld%lld", &g[i], &s[i], &b[i]);
printf("%lld\n", solve(solve(n, g[0], s[0], b[0], g[1], s[1], b[1]), g[1],
s[1], b[1], g[0], s[0], b[0]));
} | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
const lint mod = 1e9 + 7;
lint solve(int n, lint ga, lint sa, lint ba, lint gb, lint sb, lint bb) {
lint dp[n + 1];
rep(i, n + 1) dp[i] = -1;
dp[0] = 0;
rep(i, n + 1) if (dp[i] >= 0) {
if (i + ga <= n)
dp[i + ga] = max(dp[i + ga], dp[i] + gb);
if (i + sa <= n)
dp[i + sa] = max(dp[i + sa], dp[i] + sb);
if (i + ba <= n)
dp[i + ba] = max(dp[i + ba], dp[i] + bb);
}
lint ret = 0;
rep(i, n + 1) ret = max(ret, dp[i] + n - i);
return ret;
}
int main() {
int n;
scanf("%d", &n);
lint g[2], s[2], b[2];
rep(i, 2) scanf("%lld%lld%lld", &g[i], &s[i], &b[i]);
printf("%lld\n", solve(solve(n, g[0], s[0], b[0], g[1], s[1], b[1]), g[1],
s[1], b[1], g[0], s[0], b[0]));
} | [
"assignment.change"
] | 829,184 | 829,185 | u643840641 | cpp |
p03008 | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
ll n, a, b, c, A, B, C;
int main() {
cin >> n >> a >> b >> c >> A >> B >> C;
vl dp(n + 1);
for (int i = 0; i <= n; i++)
dp[i] = i;
for (int i = a; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + A);
for (int i = b; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + B);
for (int i = c; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + C);
n = dp[n];
dp = vl(n + 1);
for (int i = 0; i <= n; i++)
dp[i] = i;
for (int i = A; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + a);
for (int i = B; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + b);
for (int i = C; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + c);
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
ll n, a, b, c, A, B, C;
int main() {
cin >> n >> a >> b >> c >> A >> B >> C;
vl dp(n + 1);
for (int i = 0; i <= n; i++)
dp[i] = i;
for (int i = a; i <= n; i++)
dp[i] = max(dp[i], dp[i - a] + A);
for (int i = b; i <= n; i++)
dp[i] = max(dp[i], dp[i - b] + B);
for (int i = c; i <= n; i++)
dp[i] = max(dp[i], dp[i - c] + C);
n = dp[n];
dp = vl(n + 1);
for (int i = 0; i <= n; i++)
dp[i] = i;
for (int i = A; i <= n; i++)
dp[i] = max(dp[i], dp[i - A] + a);
for (int i = B; i <= n; i++)
dp[i] = max(dp[i], dp[i - B] + b);
for (int i = C; i <= n; i++)
dp[i] = max(dp[i], dp[i - C] + c);
cout << dp[n] << endl;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 829,194 | 829,195 | u434747175 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
vector<vector<int>> rate(2, vector<int>(3, 0));
int solve(int n, int pre, int post) {
vector<int> dp(n + 1, 0);
rep(i, n) dp[i] = i;
rep(i, n + 1) rep(j, 3) if (i >= rate[pre][j] && rate[pre][j] < rate[post][j])
dp[i] = max(dp[i], dp[i - rate[pre][j]] + rate[post][j]);
return dp[n];
}
signed main() {
int n;
cin >> n;
rep(i, 2) rep(j, 3) cin >> rate[i][j];
cout << solve(solve(n, 0, 1), 1, 0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
vector<vector<int>> rate(2, vector<int>(3, 0));
int solve(int n, int pre, int post) {
vector<int> dp(n + 1, 0);
rep(i, n + 1) dp[i] = i;
rep(i, n + 1) rep(j, 3) if (i >= rate[pre][j] && rate[pre][j] < rate[post][j])
dp[i] = max(dp[i], dp[i - rate[pre][j]] + rate[post][j]);
return dp[n];
}
signed main() {
int n;
cin >> n;
rep(i, 2) rep(j, 3) cin >> rate[i][j];
cout << solve(solve(n, 0, 1), 1, 0) << endl;
} | [
"assignment.change"
] | 829,236 | 829,237 | u731175398 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
long long n;
vector<int> ok;
long long a[4], b[4];
long long dp[6000], pd[26000000];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> a[1] >> a[2] >> a[3];
cin >> b[1] >> b[2] >> b[3];
if (a[1] < b[1])
ok.push_back(1);
if (a[2] < b[2])
ok.push_back(2);
if (a[3] < b[3])
ok.push_back(3);
long long v = n;
memset(dp, -1, sizeof(dp));
dp[n] = 0;
for (int i = n; i >= 1; i--) {
if (dp[i] == -1)
continue;
for (int j = 0; j < ok.size(); j++) {
if (i >= a[ok[j]]) {
dp[i - a[ok[j]]] = max(dp[i - a[ok[j]]], dp[i] + b[ok[j]]);
}
}
v = max(v, dp[i]);
}
v = max(v, dp[0]);
ok.clear();
if (a[1] > b[1])
ok.push_back(1);
if (a[2] > b[2])
ok.push_back(2);
if (a[3] > b[3])
ok.push_back(3);
n = v;
memset(pd, -1, sizeof(pd));
pd[n] = 0;
for (int i = n; i >= 1; i--) {
if (pd[i] == -1)
continue;
for (int j = 0; j < ok.size(); j++) {
if (i >= b[ok[j]]) {
pd[i - b[ok[j]]] = max(pd[i - b[ok[j]]], pd[i] + a[ok[j]]);
}
}
v = max(v, pd[i]);
}
v = max(v, pd[0]);
cout << v << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long n;
vector<int> ok;
long long a[4], b[4];
long long dp[6000], pd[26000000];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> a[1] >> a[2] >> a[3];
cin >> b[1] >> b[2] >> b[3];
if (a[1] < b[1])
ok.push_back(1);
if (a[2] < b[2])
ok.push_back(2);
if (a[3] < b[3])
ok.push_back(3);
long long v = 0;
memset(dp, -1, sizeof(dp));
dp[n] = 0;
for (int i = n; i >= 1; i--) {
if (dp[i] == -1)
continue;
for (int j = 0; j < ok.size(); j++) {
if (i >= a[ok[j]]) {
dp[i - a[ok[j]]] = max(dp[i - a[ok[j]]], dp[i] + b[ok[j]]);
}
}
v = max(v, dp[i] + i);
}
v = max(v, dp[0]);
ok.clear();
if (a[1] > b[1])
ok.push_back(1);
if (a[2] > b[2])
ok.push_back(2);
if (a[3] > b[3])
ok.push_back(3);
n = v;
memset(pd, -1, sizeof(pd));
pd[n] = 0;
for (int i = n; i >= 1; i--) {
if (pd[i] == -1)
continue;
for (int j = 0; j < ok.size(); j++) {
if (i >= b[ok[j]]) {
pd[i - b[ok[j]]] = max(pd[i - b[ok[j]]], pd[i] + a[ok[j]]);
}
}
v = max(v, pd[i] + i);
}
v = max(v, pd[0]);
cout << v << endl;
return 0;
}
| [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"assignment.change"
] | 829,238 | 829,239 | u313427116 | cpp |
p03008 | #include <iostream>
using namespace std;
const long long MAXN = 5e5 + 5;
long long a[5][5];
long long dp[MAXN];
long long m, ans;
int main() {
long long n;
cin >> n;
for (long long i = 0; i < 2; i++) {
for (long long j = 1; j <= 3; j++) {
cin >> a[i][j];
}
}
for (long long i = 0; i <= n; i++) {
dp[i] = n;
}
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= 3; j++) {
if (a[1][j] > a[0][j] && i - a[0][j] >= 0) {
dp[i] = max(dp[i], dp[i - a[0][j]] + a[1][j] - a[0][j]);
}
m = max(m, dp[i]);
}
}
for (long long i = 1; i <= m; i++) {
dp[i] = m;
}
for (long long i = 1; i <= m; i++) {
for (long long j = 1; j <= 3; j++) {
if (a[0][j] > a[1][j] && i - a[1][j] >= 0) {
dp[i] = max(dp[i], dp[i - a[1][j]] + a[0][j] - a[1][j]);
}
ans = max(ans, dp[i]);
}
}
cout << ans << endl;
} | #include <iostream>
using namespace std;
const long long MAXN = 5e7 + 5;
long long a[5][5];
long long dp[MAXN];
long long m, ans;
int main() {
long long n;
cin >> n;
for (long long i = 0; i < 2; i++) {
for (long long j = 1; j <= 3; j++) {
cin >> a[i][j];
}
}
for (long long i = 0; i <= n; i++) {
dp[i] = n;
}
m = n;
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= 3; j++) {
if (a[1][j] > a[0][j] && i - a[0][j] >= 0) {
dp[i] = max(dp[i], dp[i - a[0][j]] + a[1][j] - a[0][j]);
}
m = max(m, dp[i]);
}
}
for (long long i = 0; i <= m; i++) {
dp[i] = m;
}
for (long long i = 1; i <= m; i++) {
for (long long j = 1; j <= 3; j++) {
if (a[0][j] > a[1][j] && i - a[1][j] >= 0) {
dp[i] = max(dp[i], dp[i - a[1][j]] + a[0][j] - a[1][j]);
}
ans = max(ans, dp[i]);
}
}
cout << ans << endl;
} | [
"literal.number.change",
"expression.operation.binary.change",
"assignment.add",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 829,299 | 829,297 | u487618988 | cpp |
p03008 | // encoding:utf-8
//#include <iostream> //c++
//#include<stack> //ในใฟใใฏใซ้ขใใฆใๆๆฐใฎใใผใฟใใๆจใฆใ
//#include<queue> //ใญใฅใผใซ้ขใใฆใๆๅคใฎใใผใฟใใๆจใฆใ
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort ใจใใซใใ
#include <bits/stdc++.h> //vector,algorithm,que
#include <time.h> //ๆ้ใซใใใใฆ
#define ll long long
#define MOD 1000000007
#define INF (1 << 29)
using namespace std;
int main() {
ll N;
ll ag, as, ab;
ll bg, bs, bb;
cin >> N;
cin >> ag >> as >> ab;
cin >> bg >> bs >> bb;
vector<ll> dp(N + 1);
ll g_v = bg - ag;
ll s_v = bs - as;
ll b_v = bb - ab;
if (g_v > 0) {
for (int i = ag; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - ag] + g_v);
}
}
if (s_v > 0) {
for (int i = as; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - as] + s_v);
}
}
if (b_v > 0) {
for (int i = ab; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - ab] + b_v);
}
}
ll tmp = 0;
for (int i = 0; i < N + 1; i++) {
tmp = max(tmp, dp[i]);
}
ll M = N + tmp;
vector<ll> dp2(M + 1);
g_v = -bg + ag;
s_v = -bs + as;
b_v = -bb + ab;
if (g_v > 0) {
for (int i = bg; i < M + 1; i++) {
dp[i] = max(dp2[i], dp2[i - bg] + g_v);
}
}
if (s_v > 0) {
for (int i = bs; i < M + 1; i++) {
dp[i] = max(dp2[i], dp2[i - bs] + s_v);
}
}
if (b_v > 0) {
for (int i = bb; i < M + 1; i++) {
dp[i] = max(dp2[i], dp2[i - bb] + b_v);
}
}
tmp = 0;
for (int i = 0; i < M + 1; i++) {
tmp = max(tmp, dp2[i]);
}
ll ans = M + tmp;
cout << ans << endl;
return 0;
}
| // encoding:utf-8
//#include <iostream> //c++
//#include<stack> //ในใฟใใฏใซ้ขใใฆใๆๆฐใฎใใผใฟใใๆจใฆใ
//#include<queue> //ใญใฅใผใซ้ขใใฆใๆๅคใฎใใผใฟใใๆจใฆใ
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort ใจใใซใใ
#include <bits/stdc++.h> //vector,algorithm,que
#include <time.h> //ๆ้ใซใใใใฆ
#define ll long long
#define MOD 1000000007
#define INF (1 << 29)
using namespace std;
int main() {
ll N;
ll ag, as, ab;
ll bg, bs, bb;
cin >> N;
cin >> ag >> as >> ab;
cin >> bg >> bs >> bb;
vector<ll> dp(N + 1);
ll g_v = bg - ag;
ll s_v = bs - as;
ll b_v = bb - ab;
if (g_v > 0) {
for (int i = ag; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - ag] + g_v);
}
}
if (s_v > 0) {
for (int i = as; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - as] + s_v);
}
}
if (b_v > 0) {
for (int i = ab; i < N + 1; i++) {
dp[i] = max(dp[i], dp[i - ab] + b_v);
}
}
ll tmp = 0;
for (int i = 0; i < N + 1; i++) {
tmp = max(tmp, dp[i]);
}
ll M = N + tmp;
vector<ll> dp2(M + 1);
g_v = -bg + ag;
s_v = -bs + as;
b_v = -bb + ab;
if (g_v > 0) {
for (int i = bg; i < M + 1; i++) {
dp2[i] = max(dp2[i], dp2[i - bg] + g_v);
}
}
if (s_v > 0) {
for (int i = bs; i < M + 1; i++) {
dp2[i] = max(dp2[i], dp2[i - bs] + s_v);
}
}
if (b_v > 0) {
for (int i = bb; i < M + 1; i++) {
dp2[i] = max(dp2[i], dp2[i - bb] + b_v);
}
}
tmp = 0;
for (int i = 0; i < M + 1; i++) {
tmp = max(tmp, dp2[i]);
}
ll ans = M + tmp;
cout << ans << endl;
return 0;
}
| [
"assignment.variable.change",
"identifier.change"
] | 829,300 | 829,301 | u059210959 | cpp |
p03008 | #include <bits/stdc++.h>
#define ll long long
#define xx first
#define yy second
using namespace std;
ll a[5], b[5];
ll dp[60000000 + 5];
ll n;
inline ll calc(ll *x, ll *y, ll t) {
for (int i = 0; i <= t; ++i) {
dp[i] = 0;
for (int j = 1; j <= 3; ++j) {
if (i >= x[j]) {
dp[i] = max(dp[i], dp[i - x[j]] + y[j]);
}
}
}
for (int i = 0; i < t; ++i) {
dp[t] = max(dp[t], dp[i]);
}
return dp[t];
}
int main() {
#ifdef wll
freopen("testdata.in", "r", stdin);
#endif
scanf("%lld", &n);
for (int i = 1; i <= 3; ++i) {
scanf("%lld", &a[i]);
}
for (int i = 1; i <= 3; ++i) {
scanf("%lld", &b[i]);
}
n = calc(a, b, n);
n = calc(b, a, n);
printf("%lld\n", n);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define xx first
#define yy second
using namespace std;
ll a[5], b[5];
ll dp[50000000 + 5];
ll n;
inline ll calc(ll *x, ll *y, ll t) {
for (int i = 0; i <= t; ++i) {
dp[i] = 0;
for (int j = 1; j <= 3; ++j) {
if (i >= x[j]) {
dp[i] = max(dp[i], dp[i - x[j]] + y[j]);
}
}
}
for (int i = 0; i < t; ++i) {
dp[t] = max(dp[t], dp[i] + t - i);
}
return dp[t];
}
int main() {
#ifdef wll
freopen("testdata.in", "r", stdin);
#endif
scanf("%lld", &n);
for (int i = 1; i <= 3; ++i) {
scanf("%lld", &a[i]);
}
for (int i = 1; i <= 3; ++i) {
scanf("%lld", &b[i]);
}
n = calc(a, b, n);
n = calc(b, a, n);
printf("%lld\n", n);
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change",
"assignment.change"
] | 829,302 | 829,303 | u497614346 | cpp |
p03008 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll n, ll g1, ll s1, ll b1, ll g2, ll s2, ll b2) {
vector<ll> dp(n + max({g1, s1, b1}) + 1);
for (ll i = 0; i < n; i++) {
dp[i + g1] = max(dp[i + g1], dp[i] - g1 + g2);
dp[i + s1] = max(dp[i + s1], dp[i] - s1 + s2);
dp[i + b1] = max(dp[i + b1], dp[i] - b1 + b2);
}
return n + *max_element(begin(dp), begin(dp) + n);
}
int main() {
ll n, g1, s1, b1, g2, s2, b2;
cin >> n >> g1 >> s1 >> b1 >> g2 >> s2 >> b2;
n = f(n, g1, s1, b1, g2, s2, b2);
n = f(n, g2, s2, b2, g1, s1, b1);
cout << n << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll n, ll g1, ll s1, ll b1, ll g2, ll s2, ll b2) {
vector<ll> dp(n + max({g1, s1, b1}));
for (ll i = 0; i < n; i++) {
dp[i + g1] = max(dp[i + g1], dp[i] - g1 + g2);
dp[i + s1] = max(dp[i + s1], dp[i] - s1 + s2);
dp[i + b1] = max(dp[i + b1], dp[i] - b1 + b2);
}
return n + *max_element(begin(dp), begin(dp) + n + 1);
}
int main() {
ll n, g1, s1, b1, g2, s2, b2;
cin >> n >> g1 >> s1 >> b1 >> g2 >> s2 >> b2;
n = f(n, g1, s1, b1, g2, s2, b2);
n = f(n, g2, s2, b2, g1, s1, b1);
cout << n << endl;
}
| [
"expression.operation.binary.remove"
] | 829,335 | 829,336 | u848737670 | cpp |
p03008 | #include <bits/stdc++.h>
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define IFOR(i, m, n) for (int i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* ใใณใใฌใผใใใใพใง */
ll exchange(ll N, vector<vector<ll>> &g) {
//ไบคๆใในใ้ๅฑใ่กจใindexใฎใชในใ
vector<int> gain;
REP(i, 3) {
if (g[i][1] - g[i][0] > 0 && g[i][0] <= N)
gain.push_back(i);
}
if (gain.size() == 0)
return N;
int k, l;
if (gain.size() == 1) {
k = gain[0];
return N + (g[k][1] - g[k][0]) * (N / g[k][0]);
}
ll ret = N;
if (gain.size() == 2) {
k = gain[0];
l = gain[1];
for (int i = 0; g[k][0] * i <= N; i++) {
ll tmp = N + (g[k][1] - g[k][0]) * i +
(g[l][1] - g[l][0]) * ((N - g[k][0] * i) / g[l][0]);
if (ret < tmp)
ret = tmp;
}
return ret;
}
// 0,1,2
for (int i = 0; g[0][0] * i <= N; i++) {
for (int j = 0; g[1][0] * j <= N - g[0][0] * i; j++) {
ll tmp =
N + (g[0][1] - g[0][0]) * i + (g[1][1] - g[1][0]) * j +
(g[2][1] - g[2][0]) * ((N - g[0][0] * i - g[1][0] * j) / g[2][0]);
if (ret < tmp)
ret = tmp;
}
}
return ret;
}
int main() {
ll N;
cin >> N;
vector<vector<ll>> g(3, vector<ll>(2));
REP(i, 2) REP(j, 3) { cin >> g[j][i]; }
N = exchange(N, g);
REP(i, 3) { swap(g[i][0], g[i][1]); }
DUMP(N);
N = exchange(N, g);
cout << N << endl;
}
| #include <bits/stdc++.h>
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define IFOR(i, m, n) for (int i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* ใใณใใฌใผใใใใพใง */
ll exchange(ll N, vector<vector<ll>> &g) {
//ไบคๆใในใ้ๅฑใ่กจใindexใฎใชในใ
vector<int> gain;
REP(i, 3) {
if (g[i][1] - g[i][0] > 0 && g[i][0] <= N)
gain.push_back(i);
}
if (gain.size() == 0)
return N;
int k, l;
if (gain.size() == 1) {
k = gain[0];
return N + (g[k][1] - g[k][0]) * (N / g[k][0]);
}
ll ret = N;
if (gain.size() == 2) {
k = gain[0];
l = gain[1];
for (int i = 0; g[k][0] * i <= N; i++) {
ll tmp = N + (g[k][1] - g[k][0]) * i +
(g[l][1] - g[l][0]) * ((N - g[k][0] * i) / g[l][0]);
if (ret < tmp)
ret = tmp;
}
return ret;
}
// 0,1,2
for (int i = 0; g[0][0] * i <= N; i++) {
for (int j = 0; g[1][0] * j <= N - g[0][0] * i; j++) {
ll tmp =
N + (g[0][1] - g[0][0]) * i + (g[1][1] - g[1][0]) * j +
(g[2][1] - g[2][0]) * ((N - g[0][0] * i - g[1][0] * j) / g[2][0]);
if (ret < tmp)
ret = tmp;
}
}
return ret;
}
int main() {
ll N;
cin >> N;
vector<vector<ll>> g(3, vector<ll>(2));
REP(i, 2) REP(j, 3) { cin >> g[j][i]; }
N = exchange(N, g);
REP(i, 3) { swap(g[i][0], g[i][1]); }
N = exchange(N, g);
cout << N << endl;
} | [
"call.remove"
] | 829,337 | 829,338 | u708550576 | cpp |
p03008 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
int n;
cin >> n;
vector<ll> a(3), b(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
vector<ll> dp(n + 1);
for (int i = 0; i < 3; i++) {
if (a[i] >= b[i])
continue;
for (int j = a[i]; j <= n; j++) {
dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
}
}
ll m = 0;
for (int i = 0; i <= n; i++) {
m = max(m, dp[i] + n - i);
}
vector<ll> dp2(m + 1);
for (int i = 0; i < 3; i++) {
if (a[i] <= b[i])
continue;
for (int j = b[i]; j <= n; j++) {
dp2[j] = max(dp2[j], dp2[j - b[i]] + a[i]);
}
}
ll ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp2[i] + m - i);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
int n;
cin >> n;
vector<ll> a(3), b(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
vector<ll> dp(n + 1);
for (int i = 0; i < 3; i++) {
if (a[i] >= b[i])
continue;
for (int j = a[i]; j <= n; j++) {
dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
}
}
ll m = 0;
for (int i = 0; i <= n; i++) {
m = max(m, dp[i] + n - i);
}
vector<ll> dp2(m + 1);
for (int i = 0; i < 3; i++) {
if (a[i] <= b[i])
continue;
for (int j = b[i]; j <= m; j++) {
dp2[j] = max(dp2[j], dp2[j - b[i]] + a[i]);
}
}
ll ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp2[i] + m - i);
}
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 829,358 | 829,359 | u480806810 | cpp |
p03008 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
int n;
cin >> n;
vector<int> a(3), b(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
vector<int> dp(n + 1);
for (int i = 0; i < 3; i++) {
if (a[i] >= b[i])
continue;
for (int j = a[i]; j <= n; j++) {
dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
}
}
int m = 0;
for (int i = 0; i <= n; i++) {
m = max(m, dp[i] + n - i);
}
vector<int> dp2(m + 1);
for (int i = 0; i < 3; i++) {
if (a[i] <= b[i])
continue;
for (int j = b[i]; j <= n; j++) {
dp2[j] = max(dp2[j], dp2[j - b[i]] + a[i]);
}
}
int ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp2[i] + m - i);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
int n;
cin >> n;
vector<ll> a(3), b(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
vector<ll> dp(n + 1);
for (int i = 0; i < 3; i++) {
if (a[i] >= b[i])
continue;
for (int j = a[i]; j <= n; j++) {
dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
}
}
ll m = 0;
for (int i = 0; i <= n; i++) {
m = max(m, dp[i] + n - i);
}
vector<ll> dp2(m + 1);
for (int i = 0; i < 3; i++) {
if (a[i] <= b[i])
continue;
for (int j = b[i]; j <= m; j++) {
dp2[j] = max(dp2[j], dp2[j - b[i]] + a[i]);
}
}
ll ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp2[i] + m - i);
}
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.change",
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 829,360 | 829,359 | u480806810 | cpp |
p03016 | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define PP pair<P, P>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
template <class T> inline void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = min(a, b); }
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
random_device rnd;
mt19937_64 mt64(rnd());
uniform_int_distribution<int> engine(MIN, MAX);
return engine(mt64);
}
/*--------Library Zone!--------*/
int n, a, b, m;
struct matrix {
vector<vector<int>> mat;
matrix(int x, int y) {
mat.resize(x);
rep(i, x) mat[i].resize(y);
rep(i, x) rep(j, y) mat[i][j] = 0;
}
matrix operator+(matrix const &c) {
assert(mat.size() == c.mat.size() && mat[0].size() == c.mat[0].size());
matrix d = c;
rep(i, mat.size()) rep(j, mat[0].size()) { d.mat[i][j] += mat[i][j]; }
return d;
}
matrix operator-(matrix const &c) {
assert(mat.size() == c.mat.size() && mat[0].size() == c.mat[0].size());
matrix d = c;
rep(i, mat.size()) rep(j, mat[0].size()) { d.mat[i][j] -= mat[i][j]; }
return d;
}
matrix operator*(matrix const &c) {
assert(mat[0].size() == c.mat.size());
matrix res(mat.size(), c.mat[0].size());
rep(i, res.mat.size()) rep(j, res.mat[0].size()) rep(k, mat[0].size()) {
res.mat[i][j] += mat[i][k] * c.mat[k][j];
res.mat[i][j] %= m;
}
return res;
}
matrix pow(int x) {
assert(mat.size() == mat[0].size());
matrix res(mat.size(), mat[0].size()), p(mat.size(), mat[0].size());
p.mat = mat;
rep(i, mat.size()) res.mat[i][i] = 1;
while (x > 0) {
if (x & 1)
res = res * p;
p = p * p;
x >>= 1;
}
return res;
}
};
signed main() {
cin >> n >> a >> b >> m;
matrix ans(1, 3);
ans.mat = {{0, a, 1}};
for (int i = 1; i <= 18; i++) {
int ma = min(mod_pow(10, i, inf) - 1, a + b * (n - 1));
int mi = mod_pow(10, i - 1, inf) - 1;
if (ma < a)
continue;
int ko = ((ma - a) / b + 1);
if (mi >= a)
ko -= (mi - a) / b + 1;
if (ko < 0)
continue;
matrix p(3, 3);
p.mat[0] = {mod_pow(10, i, m), 0, 0};
p.mat[1] = {1, 1, 0};
p.mat[2] = {0, b, 1};
ans = ans * p.pow(ko);
}
cout << ans.mat[0][0] << endl;
} | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define PP pair<P, P>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
template <class T> inline void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = min(a, b); }
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
random_device rnd;
mt19937_64 mt64(rnd());
uniform_int_distribution<int> engine(MIN, MAX);
return engine(mt64);
}
/*--------Library Zone!--------*/
int n, a, b, m;
struct matrix {
vector<vector<int>> mat;
matrix(int x, int y) {
mat.resize(x);
rep(i, x) mat[i].resize(y);
rep(i, x) rep(j, y) mat[i][j] = 0;
}
matrix operator+(matrix const &c) {
assert(mat.size() == c.mat.size() && mat[0].size() == c.mat[0].size());
matrix d = c;
rep(i, mat.size()) rep(j, mat[0].size()) { d.mat[i][j] += mat[i][j]; }
return d;
}
matrix operator-(matrix const &c) {
assert(mat.size() == c.mat.size() && mat[0].size() == c.mat[0].size());
matrix d = c;
rep(i, mat.size()) rep(j, mat[0].size()) { d.mat[i][j] -= mat[i][j]; }
return d;
}
matrix operator*(matrix const &c) {
assert(mat[0].size() == c.mat.size());
matrix res(mat.size(), c.mat[0].size());
rep(i, res.mat.size()) rep(j, res.mat[0].size()) rep(k, mat[0].size()) {
res.mat[i][j] += mat[i][k] * c.mat[k][j];
res.mat[i][j] %= m;
}
return res;
}
matrix pow(int x) {
assert(mat.size() == mat[0].size());
matrix res(mat.size(), mat[0].size()), p(mat.size(), mat[0].size());
p.mat = mat;
rep(i, mat.size()) res.mat[i][i] = 1;
while (x > 0) {
if (x & 1)
res = res * p;
p = p * p;
x >>= 1;
}
return res;
}
};
signed main() {
cin >> n >> a >> b >> m;
matrix ans(1, 3);
ans.mat = {{0, a % m, 1}};
for (int i = 1; i <= 18; i++) {
int ma = min(mod_pow(10, i, inf) - 1, a + b * (n - 1));
int mi = mod_pow(10, i - 1, inf) - 1;
if (ma < a)
continue;
int ko = ((ma - a) / b + 1);
if (mi >= a)
ko -= (mi - a) / b + 1;
if (ko < 0)
continue;
matrix p(3, 3);
p.mat[0] = {mod_pow(10, i, m), 0, 0};
p.mat[1] = {1, 1, 0};
p.mat[2] = {0, b % m, 1};
ans = ans * p.pow(ko);
}
cout << ans.mat[0][0] << endl;
} | [
"assignment.change"
] | 829,603 | 829,604 | u147049801 | cpp |
p03016 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
ll mod = 19191919191919;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// modint {{{
struct modint {
long long int a;
inline modint(long long int x = 0) noexcept : a(x % mod) {}
inline long long int &value() noexcept { return a; }
inline const long long int &value() const noexcept { return a; }
inline modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
// Matrix Definition{{{
template <class T> struct Matrix {
vector<vector<T>> A;
Matrix(){};
Matrix(int n, int m) { A.assign(n, vector<T>(m, 0)); };
Matrix(int n) { A.assign(n, vector<T>(n, 0)); };
int height() const { return (A.size()); }
int width() const { return (A[0].size()); }
inline vector<T> &operator[](int k) { return (A.at(k)); }
inline const vector<T> &operator[](int k) const { return (A.at(k)); }
// ๅไฝ่กๅ
static Matrix E(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++)
mat[i][i] = 1;
return mat;
}
Matrix &operator+=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] += B[i][j];
return (*this);
}
Matrix &operator-=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] -= B[i][j];
return (*this);
}
Matrix &operator*=(const Matrix &B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < p; k++)
C[i][j] += (*this)[i][k] * B[k][j];
A.swap(C);
return (*this);
}
Matrix power(ll k) {
Matrix B = Matrix::E(height());
while (k > 0) {
if (k & 1)
B *= *this;
*this *= *this;
k >>= 1;
}
A.swap(B.A);
return *this;
}
Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
void Print() {
int n = height(), m = width();
for (int i = 0; i < n; i++) {
printf("[");
for (int j = 0; j < m; j++) {
printf("%lld%s", (*this)[i][j], j == m - 1 ? "]\n" : ",");
}
}
}
};
// }}}
int main() {
ll L, A, B;
ll M;
Scll3(L, A, B);
Scll(M);
mod = M;
Matrix<modint> ans(1, 3);
ans[0][0] = 0;
ans[0][1] = A;
ans[0][2] = 1;
ll tmp = A;
ll dig = 1;
ll maxll = A + B * (L - 1);
while (1) {
// printf ("%lld<%lld\n", tmp, dig );
if (tmp < dig) {
ll index;
if (dig < maxll) {
index = (dig - tmp + B - 1) / B;
} else {
index = (maxll - tmp + B) / B;
}
Matrix<modint> C(3, 3);
C[0][0] = dig % mod;
C[1][0] = 1;
C[1][1] = 1;
C[2][1] = B;
C[2][2] = 1;
C.power(index);
ans *= C;
// ans.Print();
// printf ("%lld\n", ans[0][0] );
tmp += index * B;
if (tmp >= maxll) {
break;
}
}
dig *= 10;
}
printf("%lld\n", ans[0][0]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
ll mod = 19191919191919;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// modint {{{
struct modint {
long long int a;
inline modint(long long int x = 0) noexcept : a(x % mod) {}
inline long long int &value() noexcept { return a; }
inline const long long int &value() const noexcept { return a; }
inline modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
// Matrix Definition{{{
template <class T> struct Matrix {
vector<vector<T>> A;
Matrix(){};
Matrix(int n, int m) { A.assign(n, vector<T>(m, 0)); };
Matrix(int n) { A.assign(n, vector<T>(n, 0)); };
int height() const { return (A.size()); }
int width() const { return (A[0].size()); }
inline vector<T> &operator[](int k) { return (A.at(k)); }
inline const vector<T> &operator[](int k) const { return (A.at(k)); }
// ๅไฝ่กๅ
static Matrix E(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++)
mat[i][i] = 1;
return mat;
}
Matrix &operator+=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] += B[i][j];
return (*this);
}
Matrix &operator-=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] -= B[i][j];
return (*this);
}
Matrix &operator*=(const Matrix &B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < p; k++)
C[i][j] += (*this)[i][k] * B[k][j];
A.swap(C);
return (*this);
}
Matrix power(ll k) {
Matrix B = Matrix::E(height());
while (k > 0) {
if (k & 1)
B *= *this;
*this *= *this;
k >>= 1;
}
A.swap(B.A);
return *this;
}
Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
void Print() {
int n = height(), m = width();
for (int i = 0; i < n; i++) {
printf("[");
for (int j = 0; j < m; j++) {
printf("%lld%s", (*this)[i][j], j == m - 1 ? "]\n" : ",");
}
}
}
};
// }}}
int main() {
ll L, A, B;
ll M;
Scll3(L, A, B);
Scll(M);
mod = M;
Matrix<modint> ans(1, 3);
ans[0][0] = 0;
ans[0][1] = A;
ans[0][2] = 1;
ll tmp = A;
ll dig = 1;
ll maxll = A + B * (L - 1);
while (1) {
// printf ("%lld<%lld\n", tmp, dig );
if (tmp < dig) {
ll index;
if (dig <= maxll) {
index = (dig - tmp + B - 1) / B;
} else {
index = (maxll - tmp + B) / B;
}
Matrix<modint> C(3, 3);
C[0][0] = dig % mod;
C[1][0] = 1;
C[1][1] = 1;
C[2][1] = B;
C[2][2] = 1;
C.power(index);
ans *= C;
// ans.Print();
// printf ("%lld\n", ans[0][0] );
tmp += index * B;
if (tmp > maxll) {
break;
}
}
dig *= 10;
}
printf("%lld\n", ans[0][0]);
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 829,607 | 829,608 | u550398291 | cpp |
p03016 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
ll mod = 19191919191919;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// modint {{{
struct modint {
long long int a;
inline modint(long long int x = 0) noexcept : a(x % mod) {}
inline long long int &value() noexcept { return a; }
inline const long long int &value() const noexcept { return a; }
inline modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
// Matrix Definition{{{
template <class T> struct Matrix {
vector<vector<T>> A;
Matrix(){};
Matrix(int n, int m) { A.assign(n, vector<T>(m, 0)); };
Matrix(int n) { A.assign(n, vector<T>(n, 0)); };
int height() const { return (A.size()); }
int width() const { return (A[0].size()); }
inline vector<T> &operator[](int k) { return (A.at(k)); }
inline const vector<T> &operator[](int k) const { return (A.at(k)); }
// ๅไฝ่กๅ
static Matrix E(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++)
mat[i][i] = 1;
return mat;
}
Matrix &operator+=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] += B[i][j];
return (*this);
}
Matrix &operator-=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] -= B[i][j];
return (*this);
}
Matrix &operator*=(const Matrix &B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < p; k++)
C[i][j] += (*this)[i][k] * B[k][j];
A.swap(C);
return (*this);
}
Matrix power(ll k) {
Matrix B = Matrix::E(height());
while (k > 0) {
if (k & 1)
B *= *this;
*this *= *this;
k >>= 1;
}
A.swap(B.A);
return *this;
}
Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
void Print() {
int n = height(), m = width();
for (int i = 0; i < n; i++) {
printf("[");
for (int j = 0; j < m; j++) {
printf("%lld%s", (*this)[i][j], j == m - 1 ? "]\n" : ",");
}
}
}
};
// }}}
int main() {
ll L, A, B;
ll M;
Scll3(L, A, B);
Scll(M);
mod = M;
Matrix<modint> ans(1, 3);
ans[0][0] = 0;
ans[0][1] = A;
ans[0][2] = 1;
ll tmp = A;
ll dig = 1;
ll maxll = A + B * (L - 1);
while (1) {
// printf ("%lld<%lld\n", tmp, dig );
if (tmp < dig) {
ll index;
if (dig < maxll) {
index = (dig - tmp + B - 1) / B;
} else {
index = (maxll - tmp + B) / B;
}
Matrix<modint> C(3, 3);
C[0][0] = dig;
C[1][0] = 1;
C[1][1] = 1;
C[2][1] = B;
C[2][2] = 1;
C.power(index);
ans *= C;
// ans.Print();
// printf ("%lld\n", ans[0][0] );
tmp += index * B;
if (tmp >= maxll) {
break;
}
}
dig *= 10;
}
printf("%lld\n", ans[0][0]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
ll mod = 19191919191919;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// modint {{{
struct modint {
long long int a;
inline modint(long long int x = 0) noexcept : a(x % mod) {}
inline long long int &value() noexcept { return a; }
inline const long long int &value() const noexcept { return a; }
inline modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
// Matrix Definition{{{
template <class T> struct Matrix {
vector<vector<T>> A;
Matrix(){};
Matrix(int n, int m) { A.assign(n, vector<T>(m, 0)); };
Matrix(int n) { A.assign(n, vector<T>(n, 0)); };
int height() const { return (A.size()); }
int width() const { return (A[0].size()); }
inline vector<T> &operator[](int k) { return (A.at(k)); }
inline const vector<T> &operator[](int k) const { return (A.at(k)); }
// ๅไฝ่กๅ
static Matrix E(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++)
mat[i][i] = 1;
return mat;
}
Matrix &operator+=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] += B[i][j];
return (*this);
}
Matrix &operator-=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
(*this)[i][j] -= B[i][j];
return (*this);
}
Matrix &operator*=(const Matrix &B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < p; k++)
C[i][j] += (*this)[i][k] * B[k][j];
A.swap(C);
return (*this);
}
Matrix power(ll k) {
Matrix B = Matrix::E(height());
while (k > 0) {
if (k & 1)
B *= *this;
*this *= *this;
k >>= 1;
}
A.swap(B.A);
return *this;
}
Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
void Print() {
int n = height(), m = width();
for (int i = 0; i < n; i++) {
printf("[");
for (int j = 0; j < m; j++) {
printf("%lld%s", (*this)[i][j], j == m - 1 ? "]\n" : ",");
}
}
}
};
// }}}
int main() {
ll L, A, B;
ll M;
Scll3(L, A, B);
Scll(M);
mod = M;
Matrix<modint> ans(1, 3);
ans[0][0] = 0;
ans[0][1] = A;
ans[0][2] = 1;
ll tmp = A;
ll dig = 1;
ll maxll = A + B * (L - 1);
while (1) {
// printf ("%lld<%lld\n", tmp, dig );
if (tmp < dig) {
ll index;
if (dig <= maxll) {
index = (dig - tmp + B - 1) / B;
} else {
index = (maxll - tmp + B) / B;
}
Matrix<modint> C(3, 3);
C[0][0] = dig % mod;
C[1][0] = 1;
C[1][1] = 1;
C[2][1] = B;
C[2][2] = 1;
C.power(index);
ans *= C;
// ans.Print();
// printf ("%lld\n", ans[0][0] );
tmp += index * B;
if (tmp > maxll) {
break;
}
}
dig *= 10;
}
printf("%lld\n", ans[0][0]);
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"assignment.change"
] | 829,609 | 829,608 | u550398291 | cpp |
p03016 | #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a;
loop1(18, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 1;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a % m;
loop1(18, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 1;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| [
"assignment.change"
] | 829,625 | 829,626 | u581122825 | cpp |
p03016 | #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a;
loop1(19, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 1;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a % m;
loop1(18, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 1;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| [
"literal.number.change",
"call.arguments.change"
] | 829,627 | 829,626 | u581122825 | cpp |
p03016 | #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a;
loop1(19, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 10;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| #include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
using M = V<V<ll>>;
const int MSIZE = 3;
ll m;
void printmat(M a) {
loop(MSIZE, i) {
loop(MSIZE, j) { cout << a[i][j] << " "; }
cout << endl;
}
}
M matmul(M a, M b) {
M ret = V<V<ll>>(MSIZE, V<ll>(MSIZE));
loop(MSIZE, i) loop(MSIZE, j) {
loop(MSIZE, s) {
ret[i][j] += a[i][s] * b[s][j] % m;
ret[i][j] %= m;
}
}
return ret;
}
int main() {
ll l, a, b;
cin >> l >> a >> b >> m;
ll crr = a;
ll x = 0, s = a % m;
loop1(18, d) {
ll last = 1;
loop(d, i) last *= 10;
last--;
last = min(last, a + b * (l - 1));
if (last < crr)
continue;
ll c = (last - crr) / b + 1;
crr += b * c;
ll shift = 1;
loop(d, i) shift = (shift * 10) % m;
M base = {{shift, 0, 0}, {1, 1, 0}, {0, b % m, 1}};
M mat = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
while (c) {
if (c % 2)
mat = matmul(mat, base);
base = matmul(base, base);
c /= 2;
}
ll nx = (x * mat[0][0] + s * mat[1][0] + mat[2][0]) % m;
ll ns = (x * mat[0][1] + s * mat[1][1] + mat[2][1]) % m;
x = nx, s = ns;
}
cout << x << endl;
return 0;
}
| [
"literal.number.change",
"call.arguments.change",
"variable_declaration.value.change"
] | 829,628 | 829,626 | u581122825 | cpp |
p03016 | // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
using namespace std;
// conversion
//------------------------------------------
inline int toint(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class t> inline string tostring(t x) {
ostringstream sout;
sout << x;
return sout.str();
}
// debug
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) \
cerr << #x << " = " << (x) << " (l" << __line__ << ")" \
<< " " << __file__ << endl
// type alias
using ll = long long;
using ull = unsigned long long;
inline bool isPower2(ull a) {
if (a == 0) {
return false;
}
return !(a & (a - 1));
}
inline ll getMaxEffectiveBit(ull a) {
ll index = -1;
for (; a != 0; a >>= 1) {
++index;
}
return index;
}
inline ll getSpecifiedBit(ull a, unsigned bit) {
return (a & (1LL << bit)) >> bit;
}
// computational complexity: o(log(max(a, b)))
inline ull getGcd(ull a, ull b) {
if (b == 0) {
return a;
}
return getGcd(b, a % b);
}
template <class Integer>
inline Integer getPower(Integer base, unsigned exponential) {
Integer result = 1;
while (exponential >= 1) {
if (exponential & 1) {
result = result * base;
}
base = base * base;
exponential >>= 1;
}
return result;
}
template <class Integer> class ResidueInteger {
private:
Integer mod_;
Integer n_;
// static Integer global_mod_;
// computational complexity: o(log(max(a, b)))
static inline pair<Integer, Integer> getBezoutsIdentitySolution(Integer a,
Integer b) {
if (b == 0) {
return {1, 0};
}
auto sol = getBezoutsIdentitySolution(b, a % b);
return {sol.second, sol.first - (a / b) * sol.second};
}
public:
static Integer global_mod_;
Integer getModValue(const Integer &n) const {
return (n % mod_ + mod_) % mod_;
}
// computational complexity: o(log(max(n, mod)))
inline Integer getModInverse(const Integer &n) const {
auto sol = getBezoutsIdentitySolution(n, mod_);
if (n * sol.first + mod_ * sol.second != 1) {
stringstream ss;
ss << "There exists no inverse of " << n << " in mod " << mod_ << ".";
throw invalid_argument(ss.str());
}
return getModValue(sol.first);
}
ResidueInteger() : mod_(global_mod_), n_(getModValue(0)) {}
ResidueInteger(Integer n) : mod_(global_mod_), n_(getModValue(n)) {}
ResidueInteger(Integer n, Integer mod) : mod_(mod), n_(getModValue(n)) {}
inline ResidueInteger operator+(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ + rhs.n_, this->mod_};
}
inline ResidueInteger operator+(const Integer &rhs) const {
return {this->n_ + getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator+(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) + rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator+=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ + rhs.n_);
return *this;
}
inline ResidueInteger &operator+=(const Integer &rhs) {
this->n_ = getModValue(this->n_ + getModValue(rhs));
return *this;
}
inline ResidueInteger operator-(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ - rhs.n_, this->mod_};
}
inline ResidueInteger operator-(const Integer &rhs) const {
return {this->n_ - getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator-(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) - rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator-=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ - rhs.n_);
return *this;
}
inline ResidueInteger &operator-=(const Integer &rhs) {
this->n_ = getModValue(this->n_ - getModValue(rhs));
return *this;
}
inline ResidueInteger operator*(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ * rhs.n_, this->mod_};
}
inline ResidueInteger operator*(const Integer &rhs) const {
return {this->n_ * getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator*(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) * rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator*=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ * rhs.n_);
return *this;
}
inline ResidueInteger &operator*=(const Integer &rhs) {
this->n_ = getModValue(this->n_ * getModValue(rhs));
return *this;
}
inline ResidueInteger operator/(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ * getModInverse(rhs.n_), this->mod_};
}
inline ResidueInteger operator/(const Integer &rhs) const {
return {this->n_ * getModInverse(getModValue(rhs)), this->mod_};
}
friend inline ResidueInteger operator/(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) * rhs.getModInverse(rhs.n_), rhs.mod_};
}
inline ResidueInteger &operator/=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ * getModInverse(rhs.n_));
return *this;
}
inline ResidueInteger &operator/=(const Integer &rhs) {
this->n_ = getModValue(this->n_ * getModInverse(getModValue(rhs)));
return *this;
}
inline bool operator==(const ResidueInteger &rhs) const {
return (this->n_ == rhs.n_) && (this->mod_ == rhs.mod_);
}
inline bool operator==(const Integer &rhs) const {
return this->n_ == getModValue(rhs);
}
friend bool operator==(const Integer &lhs, const ResidueInteger &rhs) {
return rhs.getModValue(lhs) == rhs.n_;
}
Integer getN() const { return n_; }
friend std::ostream &operator<<(std::ostream &lhs,
const ResidueInteger &rhs) {
return lhs << rhs.n_;
}
friend std::istream &operator>>(std::istream &lhs, ResidueInteger &rhs) {
lhs >> rhs.n_;
return lhs;
}
};
using rll = ResidueInteger<ll>;
ll mod = 1000000007ll;
template <> ll rll::global_mod_ = mod;
template <class Integer> class Matrix {
private:
ull rowCount_;
ull colCount_;
vector<Integer> values_;
public:
Matrix(ull rowCount = 0ULL, ull colCount = 0ULL)
: rowCount_(rowCount), colCount_(colCount),
values_(rowCount_ * colCount_) {}
ull getRowCount() const { return rowCount_; }
ull getColCount() const { return colCount_; }
Integer &operator()(ull rowIndex, ull colIndex) {
return values_[rowIndex * colCount_ + colIndex];
}
const Integer &operator()(ull rowIndex, ull colIndex) const {
return values_[rowIndex * colCount_ + colIndex];
}
inline Matrix operator*(const Matrix &rhs) const {
if (colCount_ != rhs.rowCount_) {
throw invalid_argument("The column size of the left matrix should be "
"equal to the row size of the right matrix.");
}
Matrix res(this->rowCount_, rhs.colCount_);
for (ll i = 0; i < rowCount_; ++i) {
for (ll j = 0; j < rhs.colCount_; ++j) {
for (ll k = 0; k < colCount_; ++k) {
res(i, j) += (*this)(i, k) * rhs(k, j);
}
}
}
return res;
}
friend std::ostream &operator<<(std::ostream &lhs, const Matrix &rhs) {
for (ll i = 0; i < rhs.rowCount_; ++i) {
if (i == 0) {
lhs << "[";
} else {
lhs << " ";
}
lhs << "[";
for (ll j = 0; j < rhs.colCount_; ++j) {
lhs << rhs.values_[i * rhs.colCount_ + j];
if (j + 1 < rhs.colCount_) {
lhs << ", ";
}
}
if (i + 1 < rhs.rowCount_) {
lhs << "]," << endl;
} else {
lhs << "]]";
}
}
return lhs;
}
};
template <class Integer>
inline Matrix<Integer> getPower(Matrix<Integer> base, unsigned exponential) {
if (base.getRowCount() != base.getColCount()) {
throw invalid_argument("The base matrix should be a square matrix.");
}
ull size = base.getRowCount();
Matrix<Integer> result(size, size);
for (ull i = 0; i < size; ++i) {
result(i, i) = 1;
}
while (exponential >= 1) {
if (exponential & 1) {
result = result * base;
}
base = base * base;
exponential >>= 1;
}
return result;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll L, A, B, M;
cin >> L >> A >> B >> M;
rll::global_mod_ = M;
using mat = Matrix<rll>;
rll res = 0;
ll prev_index = 0, curr_index;
ll base = 1;
for (ll i = 1; prev_index < L && i <= 20; prev_index = curr_index, ++i) {
base *= 10;
curr_index = min(max((base - A + B - 1) / B, curr_index), L);
if (curr_index <= prev_index) {
continue;
}
mat recurrenceMatrix(4, 4);
recurrenceMatrix(0, 0) = rll(base), recurrenceMatrix(0, 1) = 0,
recurrenceMatrix(0, 2) = 0, recurrenceMatrix(0, 3) = 0,
recurrenceMatrix(1, 0) = rll(base),
recurrenceMatrix(1, 1) = rll(base),
recurrenceMatrix(1, 2) = 0, recurrenceMatrix(1, 3) = 0,
recurrenceMatrix(2, 0) = 1, recurrenceMatrix(2, 1) = 0,
recurrenceMatrix(2, 2) = 1, recurrenceMatrix(2, 3) = 0,
recurrenceMatrix(3, 0) = 0, recurrenceMatrix(3, 1) = 1,
recurrenceMatrix(3, 2) = 0, recurrenceMatrix(3, 3) = 1;
mat initialMatrix(4, 1);
initialMatrix(0, 0) = 1, initialMatrix(1, 0) = 0, initialMatrix(2, 0) = 0,
initialMatrix(3, 0) = 0;
ll sequenceLength = curr_index - prev_index;
mat resultingMatrix =
getPower(recurrenceMatrix, sequenceLength) * initialMatrix;
rll sumR = resultingMatrix(2, 0), sumNR = resultingMatrix(3, 0);
res *= getPower(getPower(rll(10), sequenceLength), i);
res += (rll(A) + rll(B) * (curr_index - 1)) * sumR - rll(B) * sumNR;
}
cout << res << endl;
return 0;
}
| // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
using namespace std;
// conversion
//------------------------------------------
inline int toint(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class t> inline string tostring(t x) {
ostringstream sout;
sout << x;
return sout.str();
}
// debug
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) \
cerr << #x << " = " << (x) << " (l" << __line__ << ")" \
<< " " << __file__ << endl
// type alias
using ll = long long;
using ull = unsigned long long;
inline bool isPower2(ull a) {
if (a == 0) {
return false;
}
return !(a & (a - 1));
}
inline ll getMaxEffectiveBit(ull a) {
ll index = -1;
for (; a != 0; a >>= 1) {
++index;
}
return index;
}
inline ll getSpecifiedBit(ull a, unsigned bit) {
return (a & (1LL << bit)) >> bit;
}
// computational complexity: o(log(max(a, b)))
inline ull getGcd(ull a, ull b) {
if (b == 0) {
return a;
}
return getGcd(b, a % b);
}
template <class Integer>
inline Integer getPower(Integer base, ull exponential) {
Integer result = 1;
while (exponential >= 1) {
if (exponential & 1) {
result = result * base;
}
base = base * base;
exponential >>= 1;
}
return result;
}
template <class Integer> class ResidueInteger {
private:
Integer mod_;
Integer n_;
// static Integer global_mod_;
// computational complexity: o(log(max(a, b)))
static inline pair<Integer, Integer> getBezoutsIdentitySolution(Integer a,
Integer b) {
if (b == 0) {
return {1, 0};
}
auto sol = getBezoutsIdentitySolution(b, a % b);
return {sol.second, sol.first - (a / b) * sol.second};
}
public:
static Integer global_mod_;
Integer getModValue(const Integer &n) const {
return (n % mod_ + mod_) % mod_;
}
// computational complexity: o(log(max(n, mod)))
inline Integer getModInverse(const Integer &n) const {
auto sol = getBezoutsIdentitySolution(n, mod_);
if (n * sol.first + mod_ * sol.second != 1) {
stringstream ss;
ss << "There exists no inverse of " << n << " in mod " << mod_ << ".";
throw invalid_argument(ss.str());
}
return getModValue(sol.first);
}
ResidueInteger() : mod_(global_mod_), n_(getModValue(0)) {}
ResidueInteger(Integer n) : mod_(global_mod_), n_(getModValue(n)) {}
ResidueInteger(Integer n, Integer mod) : mod_(mod), n_(getModValue(n)) {}
inline ResidueInteger operator+(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ + rhs.n_, this->mod_};
}
inline ResidueInteger operator+(const Integer &rhs) const {
return {this->n_ + getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator+(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) + rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator+=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ + rhs.n_);
return *this;
}
inline ResidueInteger &operator+=(const Integer &rhs) {
this->n_ = getModValue(this->n_ + getModValue(rhs));
return *this;
}
inline ResidueInteger operator-(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ - rhs.n_, this->mod_};
}
inline ResidueInteger operator-(const Integer &rhs) const {
return {this->n_ - getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator-(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) - rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator-=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ - rhs.n_);
return *this;
}
inline ResidueInteger &operator-=(const Integer &rhs) {
this->n_ = getModValue(this->n_ - getModValue(rhs));
return *this;
}
inline ResidueInteger operator*(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ * rhs.n_, this->mod_};
}
inline ResidueInteger operator*(const Integer &rhs) const {
return {this->n_ * getModValue(rhs), this->mod_};
}
friend inline ResidueInteger operator*(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) * rhs.n_, rhs.mod_};
}
inline ResidueInteger &operator*=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ * rhs.n_);
return *this;
}
inline ResidueInteger &operator*=(const Integer &rhs) {
this->n_ = getModValue(this->n_ * getModValue(rhs));
return *this;
}
inline ResidueInteger operator/(const ResidueInteger &rhs) const {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
return {this->n_ * getModInverse(rhs.n_), this->mod_};
}
inline ResidueInteger operator/(const Integer &rhs) const {
return {this->n_ * getModInverse(getModValue(rhs)), this->mod_};
}
friend inline ResidueInteger operator/(const Integer &lhs,
const ResidueInteger &rhs) {
return {rhs.getModValue(lhs) * rhs.getModInverse(rhs.n_), rhs.mod_};
}
inline ResidueInteger &operator/=(const ResidueInteger &rhs) {
if (this->mod_ != rhs.mod_) {
throw invalid_argument("The mods of both operands should be equal.");
}
this->n_ = getModValue(this->n_ * getModInverse(rhs.n_));
return *this;
}
inline ResidueInteger &operator/=(const Integer &rhs) {
this->n_ = getModValue(this->n_ * getModInverse(getModValue(rhs)));
return *this;
}
inline bool operator==(const ResidueInteger &rhs) const {
return (this->n_ == rhs.n_) && (this->mod_ == rhs.mod_);
}
inline bool operator==(const Integer &rhs) const {
return this->n_ == getModValue(rhs);
}
friend bool operator==(const Integer &lhs, const ResidueInteger &rhs) {
return rhs.getModValue(lhs) == rhs.n_;
}
Integer getN() const { return n_; }
friend std::ostream &operator<<(std::ostream &lhs,
const ResidueInteger &rhs) {
return lhs << rhs.n_;
}
friend std::istream &operator>>(std::istream &lhs, ResidueInteger &rhs) {
lhs >> rhs.n_;
return lhs;
}
};
using rll = ResidueInteger<ll>;
ll mod = 1000000007ll;
template <> ll rll::global_mod_ = mod;
template <class Integer> class Matrix {
private:
ull rowCount_;
ull colCount_;
vector<Integer> values_;
public:
Matrix(ull rowCount = 0ULL, ull colCount = 0ULL)
: rowCount_(rowCount), colCount_(colCount),
values_(rowCount_ * colCount_) {}
ull getRowCount() const { return rowCount_; }
ull getColCount() const { return colCount_; }
Integer &operator()(ull rowIndex, ull colIndex) {
return values_[rowIndex * colCount_ + colIndex];
}
const Integer &operator()(ull rowIndex, ull colIndex) const {
return values_[rowIndex * colCount_ + colIndex];
}
inline Matrix operator*(const Matrix &rhs) const {
if (colCount_ != rhs.rowCount_) {
throw invalid_argument("The column size of the left matrix should be "
"equal to the row size of the right matrix.");
}
Matrix res(this->rowCount_, rhs.colCount_);
for (ll i = 0; i < rowCount_; ++i) {
for (ll j = 0; j < rhs.colCount_; ++j) {
for (ll k = 0; k < colCount_; ++k) {
res(i, j) += (*this)(i, k) * rhs(k, j);
}
}
}
return res;
}
friend std::ostream &operator<<(std::ostream &lhs, const Matrix &rhs) {
for (ll i = 0; i < rhs.rowCount_; ++i) {
if (i == 0) {
lhs << "[";
} else {
lhs << " ";
}
lhs << "[";
for (ll j = 0; j < rhs.colCount_; ++j) {
lhs << rhs.values_[i * rhs.colCount_ + j];
if (j + 1 < rhs.colCount_) {
lhs << ", ";
}
}
if (i + 1 < rhs.rowCount_) {
lhs << "]," << endl;
} else {
lhs << "]]";
}
}
return lhs;
}
};
template <class Integer>
inline Matrix<Integer> getPower(Matrix<Integer> base, ull exponential) {
if (base.getRowCount() != base.getColCount()) {
throw invalid_argument("The base matrix should be a square matrix.");
}
ull size = base.getRowCount();
Matrix<Integer> result(size, size);
for (ull i = 0; i < size; ++i) {
result(i, i) = 1;
}
while (exponential >= 1) {
if (exponential & 1) {
result = result * base;
}
base = base * base;
exponential >>= 1;
}
return result;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll L, A, B, M;
cin >> L >> A >> B >> M;
rll::global_mod_ = M;
using mat = Matrix<rll>;
rll res = 0;
ll prev_index = 0, curr_index;
ll base = 1;
for (ll i = 1; prev_index < L && i <= 20; prev_index = curr_index, ++i) {
base *= 10;
curr_index = min(max((base - A + B - 1) / B, prev_index), L);
if (curr_index <= prev_index) {
continue;
}
mat recurrenceMatrix(4, 4);
recurrenceMatrix(0, 0) = rll(base), recurrenceMatrix(0, 1) = 0,
recurrenceMatrix(0, 2) = 0, recurrenceMatrix(0, 3) = 0,
recurrenceMatrix(1, 0) = rll(base),
recurrenceMatrix(1, 1) = rll(base),
recurrenceMatrix(1, 2) = 0, recurrenceMatrix(1, 3) = 0,
recurrenceMatrix(2, 0) = 1, recurrenceMatrix(2, 1) = 0,
recurrenceMatrix(2, 2) = 1, recurrenceMatrix(2, 3) = 0,
recurrenceMatrix(3, 0) = 0, recurrenceMatrix(3, 1) = 1,
recurrenceMatrix(3, 2) = 0, recurrenceMatrix(3, 3) = 1;
mat initialMatrix(4, 1);
initialMatrix(0, 0) = 1, initialMatrix(1, 0) = 0, initialMatrix(2, 0) = 0,
initialMatrix(3, 0) = 0;
ll sequenceLength = curr_index - prev_index;
mat resultingMatrix =
getPower(recurrenceMatrix, sequenceLength) * initialMatrix;
rll sumR = resultingMatrix(2, 0), sumNR = resultingMatrix(3, 0);
res *= getPower(getPower(rll(10), sequenceLength), i);
res += (rll(A) + rll(B) * (curr_index - 1)) * sumR - rll(B) * sumNR;
}
cout << res << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 829,635 | 829,634 | u331542638 | cpp |
p03016 | #include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX / 1000
#define P pair<int, int>
#define prique priority_queue
using namespace std;
class matrix {
int n;
vector<vector<int>> vec;
void letMeasure() {
rep(i, n) {
rep(j, n) {
if (i != j)
vec[i][j] = 0;
else
vec[i][j] = 1;
}
}
}
public:
matrix(int n) {
this->n = n;
vec.resize(n, vector<int>(n));
}
matrix(int n, vector<int> vec) {
if (vec.size() != n * n) {
cerr << "Invalid construct of matrix" << endl;
exit(1);
}
this->n = n;
this->vec.resize(n, vector<int>(n));
rep(i, n) { rep(j, n) this->vec[i][j] = vec[i * n + j]; }
}
int operator[](int a) { return vec[a / n][a % n]; }
unsigned int size() { return n; }
matrix operator*(const matrix a) {
if (this->n != a.n) {
cerr << "Invalid maltiply of matrix" << endl;
exit(1);
}
vector<int> memo(n);
rep(i, n) {
rep(j, n) {
rep(k, n) { memo[j] += vec[i][k] * a.vec[k][j]; }
}
vec[i] = memo;
memo.clear();
memo.resize(n);
}
return *this;
}
matrix letmod(int m) {
rep(i, n) { rep(j, n) vec[i][j] %= m; }
return *this;
}
static matrix measure(int n) {
matrix res(n);
res.letMeasure();
return res;
}
};
matrix mypow(matrix a, int b, int m) {
a.letmod(m);
if (!b)
return matrix::measure(a.size());
if (b % 2)
return (mypow(a, b - 1, m) * a).letmod(m);
matrix memo = mypow(a, b / 2, m);
return (memo * memo).letmod(m);
}
int mypow(int a, int b) {
if (!b)
return 1;
if (b % 2)
return mypow(a, b - 1) * a;
int memo = mypow(a, b / 2);
return memo * memo;
}
int l, a, b, m;
signed main() {
cin >> l >> a >> b >> m;
int c = a + b * (l - 1);
int ans[3] = {0, a % m, 1};
for (int i = 1; i <= 18; i++) {
if (mypow(10, i) <= a)
continue;
int cnt;
if (mypow(10, i) >= c) {
if (mypow(10, i - 1) >= a)
cnt = (c - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
else
cnt = (c - a + b) / b;
} else {
if (mypow(10, i - 1) >= a)
cnt =
(mypow(10, i) - 1 - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
else
cnt = (mypow(10, i) - 1 - a + b) / b;
}
if (cnt < 0)
break;
vector<int> vec{mypow(10, i) % m, 0, 0, 1, 1, 0, 0, b % m, 1};
matrix mat(3, vec);
mat = mypow(mat, cnt, m);
int memo[3] = {ans[0], ans[1], ans[2]};
ans[0] =
(memo[0] * mat[0] % m + memo[1] * mat[3] % m + memo[2] * mat[6] % m) %
m;
ans[1] =
(memo[0] * mat[1] % m + memo[1] * mat[4] % m + memo[2] * mat[7] % m) %
m;
}
cout << ans[0] << endl;
} | #include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX / 1000
#define P pair<int, int>
#define prique priority_queue
using namespace std;
class matrix {
int n;
vector<vector<int>> vec;
void letMeasure() {
rep(i, n) {
rep(j, n) {
if (i != j)
vec[i][j] = 0;
else
vec[i][j] = 1;
}
}
}
public:
matrix(int n) {
this->n = n;
vec.resize(n, vector<int>(n));
}
matrix(int n, vector<int> vec) {
if (vec.size() != n * n) {
cerr << "Invalid construct of matrix" << endl;
exit(1);
}
this->n = n;
this->vec.resize(n, vector<int>(n));
rep(i, n) { rep(j, n) this->vec[i][j] = vec[i * n + j]; }
}
int operator[](int a) { return vec[a / n][a % n]; }
unsigned int size() { return n; }
matrix operator*(const matrix a) {
if (this->n != a.n) {
cerr << "Invalid maltiply of matrix" << endl;
exit(1);
}
vector<int> memo(n);
rep(i, n) {
rep(j, n) {
rep(k, n) { memo[j] += vec[i][k] * a.vec[k][j]; }
}
vec[i] = memo;
memo.clear();
memo.resize(n);
}
return *this;
}
matrix letmod(int m) {
rep(i, n) { rep(j, n) vec[i][j] %= m; }
return *this;
}
static matrix measure(int n) {
matrix res(n);
res.letMeasure();
return res;
}
};
matrix mypow(matrix a, int b, int m) {
a.letmod(m);
if (!b)
return matrix::measure(a.size());
if (b % 2)
return (mypow(a, b - 1, m) * a).letmod(m);
matrix memo = mypow(a, b / 2, m);
return (memo * memo).letmod(m);
}
int mypow(int a, int b) {
if (!b)
return 1;
if (b % 2)
return mypow(a, b - 1) * a;
int memo = mypow(a, b / 2);
return memo * memo;
}
int l, a, b, m;
signed main() {
cin >> l >> a >> b >> m;
int c = a + b * (l - 1);
int ans[3] = {0, a % m, 1};
for (int i = 1; i <= 18; i++) {
if (mypow(10, i) <= a)
continue;
int cnt;
if (mypow(10, i) > c) {
if (mypow(10, i - 1) >= a)
cnt = (c - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
else
cnt = (c - a + b) / b;
} else {
if (mypow(10, i - 1) >= a)
cnt =
(mypow(10, i) - 1 - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
else
cnt = (mypow(10, i) - 1 - a + b) / b;
}
if (cnt < 0)
break;
vector<int> vec{mypow(10, i) % m, 0, 0, 1, 1, 0, 0, b % m, 1};
matrix mat(3, vec);
mat = mypow(mat, cnt, m);
int memo[3] = {ans[0], ans[1], ans[2]};
ans[0] =
(memo[0] * mat[0] % m + memo[1] * mat[3] % m + memo[2] * mat[6] % m) %
m;
ans[1] =
(memo[0] * mat[1] % m + memo[1] * mat[4] % m + memo[2] * mat[7] % m) %
m;
}
cout << ans[0] << endl;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 829,640 | 829,641 | u379822620 | cpp |
p03016 | #include <bits/stdc++.h>
#define IO_OP \
std::ios::sync_with_stdio(0); \
std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
const int INF = 1e9 + 7;
int m;
class M {
public:
ll a[3][3];
M() { memset(a, 0, sizeof a); }
M operator*(M b) {
M c;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
c.a[i][j] += a[i][k] * b.a[k][j] % m;
c.a[i][j] %= m;
}
}
}
return c;
}
};
M pw(M A, int b) {
if (b == 0) {
M id;
for (int i = 0; i < 3; i++)
id.a[i][i] = 1;
return id;
}
M T = pw(A, b / 2);
if (b & 1) {
return T * T * A;
} else {
return T * T;
}
}
int32_t main() {
IO_OP;
int L, a, b, p = 1;
cin >> L >> a >> b >> m;
M v;
v.a[0][0] = 0, v.a[1][0] = a, v.a[2][0] = b;
for (int w = 1; w <= 18; w++, p *= 10) {
int l = max((p - a + b - 1) / b + 1, 1LL);
int r = (p * 10 - a + b - 1) / b;
// cout << l << " " << r << endl;
// cout << v.a[0][0] << endl;
if (l > L)
break;
if (r < l)
continue;
r = min(r, L);
int k = r - l + 1;
M A;
A.a[0][0] = p * 10 % m;
A.a[0][1] = 1;
A.a[1][1] = 1;
A.a[1][2] = 1;
A.a[2][2] = 1;
A = pw(A, k);
v = A * v;
}
cout << v.a[0][0] << endl;
}
| #include <bits/stdc++.h>
#define IO_OP \
std::ios::sync_with_stdio(0); \
std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
const int INF = 1e9 + 7;
int m;
class M {
public:
ll a[3][3];
M() { memset(a, 0, sizeof a); }
M operator*(M b) {
M c;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
c.a[i][j] += a[i][k] * b.a[k][j] % m;
c.a[i][j] %= m;
}
}
}
return c;
}
};
M pw(M A, int b) {
if (b == 0) {
M id;
for (int i = 0; i < 3; i++)
id.a[i][i] = 1;
return id;
}
M T = pw(A, b / 2);
if (b & 1) {
return T * T * A;
} else {
return T * T;
}
}
int32_t main() {
IO_OP;
int L, a, b, p = 1;
cin >> L >> a >> b >> m;
M v;
v.a[0][0] = 0, v.a[1][0] = a % m, v.a[2][0] = b % m;
for (int w = 1; w <= 18; w++, p *= 10) {
int l = max((p - a + b - 1) / b + 1, 1LL);
int r = (p * 10 - a + b - 1) / b;
// cout << l << " " << r << endl;
// cout << v.a[0][0] << endl;
if (l > L)
break;
if (r < l)
continue;
r = min(r, L);
int k = r - l + 1;
M A;
A.a[0][0] = p * 10 % m;
A.a[0][1] = 1;
A.a[1][1] = 1;
A.a[1][2] = 1;
A.a[2][2] = 1;
A = pw(A, k);
v = A * v;
}
cout << v.a[0][0] << endl;
}
| [
"assignment.change"
] | 829,645 | 829,646 | u454290303 | cpp |
p03016 | // warm heart, wagging tail,and a smile just for you!
// โโโโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโโโ
// โโโโโโโโโโโ
// โโโฌโฌโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโฌโฌโฌโฌโฌโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโโโโโโโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโโโโ
// โโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโโโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโ
// โโโโโโโ โโโโโ
// โโโโโโโโโโโโโโโโโโโ
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int m, M;
vec matmul(vec &dp, mat &mt) {
vec ret(m, 0);
REP(i, m) REP(j, m) ret[i] += mt[i][j] * dp[j], ret[i] %= M;
return ret;
}
mat update(mat &mt) {
mat ret(m, vec(m, 0));
REP(i, m)
REP(j, m) REP(k, m) ret[i][j] += mt[i][k] * mt[k][j],
ret[i][j] %= M;
return ret;
}
void matpow(vec &dp, mat &mt, int k) {
m = dp.size();
while (k) {
if (k % 2)
dp = matmul(dp, mt);
mt = update(mt);
k /= 2;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int l, a, b;
cin >> l >> a >> b >> M;
int ans = 0, cnt = 1, now = a;
while (cnt < a)
cnt *= 10;
while (now < a + b * (l - 1)) {
int k = (min(cnt - 1, a + b * (l - 1)) - a) / b - (now - a) / b + 1;
// debug(k);
vec dp = {ans, now % M, b % M};
mat mt(3, vec(3, 0));
mt[0][0] = cnt % M;
mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
matpow(dp, mt, k);
ans = dp[0];
// debug(ans);
now += k * b;
// debug(now);
cnt *= 10;
// debug(cnt);
}
cout << ans << endl;
return 0;
} | // warm heart, wagging tail,and a smile just for you!
// โโโโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโโโ
// โโโโโโโโโโโ
// โโโฌโฌโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโฌโฌโฌโฌโฌโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโโโโโโโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโโโโ
// โโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโโโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโ
// โโโโโโโ โโโโโ
// โโโโโโโโโโโโโโโโโโโ
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int m, M;
vec matmul(vec &dp, mat &mt) {
vec ret(m, 0);
REP(i, m) REP(j, m) ret[i] += mt[i][j] * dp[j], ret[i] %= M;
return ret;
}
mat update(mat &mt) {
mat ret(m, vec(m, 0));
REP(i, m)
REP(j, m) REP(k, m) ret[i][j] += mt[i][k] * mt[k][j],
ret[i][j] %= M;
return ret;
}
void matpow(vec &dp, mat &mt, int k) {
m = dp.size();
while (k) {
if (k % 2)
dp = matmul(dp, mt);
mt = update(mt);
k /= 2;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int l, a, b;
cin >> l >> a >> b >> M;
int ans = 0, cnt = 1, now = a;
while (cnt < a)
cnt *= 10;
while (now <= a + b * (l - 1)) {
int k = (min(cnt - 1, a + b * (l - 1)) - a) / b - (now - a) / b + 1;
// debug(k);
vec dp = {ans, now % M, b % M};
mat mt(3, vec(3, 0));
mt[0][0] = cnt % M;
mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
matpow(dp, mt, k);
ans = dp[0];
// debug(ans);
now += k * b;
// debug(now);
cnt *= 10;
// debug(cnt);
}
cout << ans << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 829,657 | 829,658 | u239493918 | cpp |
p03016 | // warm heart, wagging tail,and a smile just for you!
// โโโโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโโโ
// โโโโโโโโโโโ
// โโโฌโฌโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโฌโฌโฌโฌโฌโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโโโโโโโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโโโโ
// โโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโโโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโ
// โโโโโโโ โโโโโ
// โโโโโโโโโโโโโโโโโโโ
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int m, M;
vec matmul(vec &dp, mat &mt) {
vec ret(m, 0);
REP(i, m) REP(j, m) ret[i] += (mt[i][j] * dp[j]) % M, ret[i] %= M;
return ret;
}
mat update(mat &mt) {
mat ret(m, vec(m, 0));
REP(i, m)
REP(j, m) REP(k, m) ret[i][j] += (mt[i][k] * mt[k][j]) % M,
ret[i][j] %= M;
return ret;
}
void matpow(vec &dp, mat &mt, int k) {
m = dp.size();
while (k) {
if (k % 2)
dp = matmul(dp, mt);
mt = update(mt);
k /= 2;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int l, a, b;
cin >> l >> a >> b >> M;
int ans = 0, cnt = 1, now = a;
while (cnt < a)
cnt *= 10;
while (now < a + b * (l - 1)) {
int k = (min(cnt - 1, a + b * (l - 1)) - a) / b - (now - a) / b + 1;
// debug(k);
vec dp = {ans % M, now % M, b % M};
mat mt(3, vec(3, 0));
mt[0][0] = cnt % M;
mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
matpow(dp, mt, k);
ans = dp[0];
// debug(ans);
now += k * b;
// debug(now);
cnt *= 10;
// debug(cnt);
}
cout << ans << endl;
return 0;
} | // warm heart, wagging tail,and a smile just for you!
// โโโโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโโโ
// โโโโโโโโโโโ
// โโโฌโฌโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโฌโฌโฌโฌโฌโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโ
// โโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโโโโโโโฌโฌโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโโโโ
// โโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโโโฌโฌโฌโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโโโฌโฌโฌโโโโโฌโฌโโโโโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโโโ
// โโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโโโ
// โโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโโโฌโฌโฌโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโ
// โโโโโโโโโโโโโโ
// โโโโโฌโฌโฌโฌโฌโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโฌโฌโฌโฌโโโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโฌโโโโ
// โโโโโโโ โโโโโ
// โโโโโโโโโโโโโโโโโโโ
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int m, M;
vec matmul(vec &dp, mat &mt) {
vec ret(m, 0);
REP(i, m) REP(j, m) ret[i] += (mt[i][j] * dp[j]) % M, ret[i] %= M;
return ret;
}
mat update(mat &mt) {
mat ret(m, vec(m, 0));
REP(i, m)
REP(j, m) REP(k, m) ret[i][j] += (mt[i][k] * mt[k][j]) % M,
ret[i][j] %= M;
return ret;
}
void matpow(vec &dp, mat &mt, int k) {
m = dp.size();
while (k) {
if (k % 2)
dp = matmul(dp, mt);
mt = update(mt);
k /= 2;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int l, a, b;
cin >> l >> a >> b >> M;
int ans = 0, cnt = 1, now = a;
while (cnt < a)
cnt *= 10;
while (now <= a + b * (l - 1)) {
int k = (min(cnt - 1, a + b * (l - 1)) - a) / b - (now - a) / b + 1;
// debug(k);
vec dp = {ans % M, now % M, b % M};
mat mt(3, vec(3, 0));
mt[0][0] = cnt % M;
mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
matpow(dp, mt, k);
ans = dp[0];
// debug(ans);
now += k * b;
// debug(now);
cnt *= 10;
// debug(cnt);
}
cout << ans << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 829,659 | 829,660 | u239493918 | cpp |
p03016 | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
#define popcount __builtin_popcount
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) {
t = q.top();
q.pop();
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) {
return b = b & t;
}
template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) {
return b = b ^ t;
}
template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) {
return b = b | t;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int e5 = 1e5;
const int e9 = 1e9;
const int MD = 1e9 + 7;
const ll e18 = 1e18;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T> T &chmax(T &a, T b) { return a = max(a, b); }
template <typename T> T &chmin(T &a, T b) { return a = min(a, b); }
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
ll maxflow(vector<mil> &E, int s, int t) {
ll z = 0;
vi b(E.size(), -1);
for (int i = 0;; ++i) {
static auto dfs = [&](int v, ll f, auto &dfs) -> ll {
if (v == t)
return f;
b[v] = i;
for (auto &p : E[v]) {
if (b[p.first] < i && p.second) {
if (ll r = dfs(p.first, min(f, p.second), dfs)) {
p.second -= r;
E[p.first][v] += r;
return r;
}
}
}
return 0;
};
ll x = dfs(s, ll(1e18), dfs);
z += x;
if (x == 0)
return z;
}
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, s;
void extend(int N) {
foor(i, p.size(), N) {
p << i;
s << 1;
}
}
public:
UnionFind(void) {}
UnionFind(int N) { extend(N - 1); }
int find(int i) {
extend(i);
return p[i] = p[i] == i ? i : find(p[i]);
}
void unite(int a, int b) {
extend(a);
extend(b);
if ((a = find(a)) != (b = find(b))) {
if (s[a] > s[b]) {
swap(a, b);
}
s[b] += s[a];
p[a] = b;
}
}
void unite(pii p) { return unite(p.first, p.second); }
bool same(int a, int b) {
extend(a);
extend(b);
return find(a) == find(b);
}
bool same(pii p) { return same(p.first, p.second); }
int size(int x) {
extend(x);
return s[find(x)];
}
};
ll MST(vector<pair<ll, pii>> &E) {
Sort(E);
UnionFind uf;
ll z = 0;
for (auto &e : E) {
if (!uf.same(e.second)) {
z += e.first;
uf.unite(e.second);
}
}
return z;
}
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) {
assert(x != 0);
return pow(x, p - 2, p);
}
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
assert(n < p);
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
ll F(int n) { return n < 0 ? 0 : f[n].first; }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll L, A, B, M;
cin >> L >> A >> B >> M;
ll SL = A + B * (L - 1);
ll z = 0;
foor(i, to_string(A).size(), to_string(SL).size()) {
ll p10 = 1;
fr(j, i) { p10 *= 10; }
print(p10);
ll T = min(p10 - 1, SL) - A;
T = T >= 0 ? T / B + 1 : 0;
ll C = 1, D = 0, E = 0, F = 0, k = 0;
for (int j = 0; T >> j; ++j) {
ll P = pow(p10, 1ll << j, M);
if (T >> j & 1) {
E = (E * P % M + D + C * k % M) % M;
F = (F * P % M + C) % M;
k = (k + (1ll << j)) % M;
}
D = (D * (P + 1) % M + C * pow(2, j, M) % M) % M;
C = C * (P + 1) % M;
}
E = (B % M * E % M + A % M * F % M) % M;
z = (z * pow(p10, T, M) % M + E) % M;
A = A + T * B;
}
print(z);
return 0;
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
#define popcount __builtin_popcount
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) {
t = q.top();
q.pop();
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) {
return b = b & t;
}
template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) {
return b = b ^ t;
}
template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) {
return b = b | t;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int e5 = 1e5;
const int e9 = 1e9;
const int MD = 1e9 + 7;
const ll e18 = 1e18;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T> T &chmax(T &a, T b) { return a = max(a, b); }
template <typename T> T &chmin(T &a, T b) { return a = min(a, b); }
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
ll maxflow(vector<mil> &E, int s, int t) {
ll z = 0;
vi b(E.size(), -1);
for (int i = 0;; ++i) {
static auto dfs = [&](int v, ll f, auto &dfs) -> ll {
if (v == t)
return f;
b[v] = i;
for (auto &p : E[v]) {
if (b[p.first] < i && p.second) {
if (ll r = dfs(p.first, min(f, p.second), dfs)) {
p.second -= r;
E[p.first][v] += r;
return r;
}
}
}
return 0;
};
ll x = dfs(s, ll(1e18), dfs);
z += x;
if (x == 0)
return z;
}
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, s;
void extend(int N) {
foor(i, p.size(), N) {
p << i;
s << 1;
}
}
public:
UnionFind(void) {}
UnionFind(int N) { extend(N - 1); }
int find(int i) {
extend(i);
return p[i] = p[i] == i ? i : find(p[i]);
}
void unite(int a, int b) {
extend(a);
extend(b);
if ((a = find(a)) != (b = find(b))) {
if (s[a] > s[b]) {
swap(a, b);
}
s[b] += s[a];
p[a] = b;
}
}
void unite(pii p) { return unite(p.first, p.second); }
bool same(int a, int b) {
extend(a);
extend(b);
return find(a) == find(b);
}
bool same(pii p) { return same(p.first, p.second); }
int size(int x) {
extend(x);
return s[find(x)];
}
};
ll MST(vector<pair<ll, pii>> &E) {
Sort(E);
UnionFind uf;
ll z = 0;
for (auto &e : E) {
if (!uf.same(e.second)) {
z += e.first;
uf.unite(e.second);
}
}
return z;
}
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) {
assert(x != 0);
return pow(x, p - 2, p);
}
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
assert(n < p);
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
ll F(int n) { return n < 0 ? 0 : f[n].first; }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll L, A, B, M;
cin >> L >> A >> B >> M;
ll SL = A + B * (L - 1);
ll z = 0;
foor(i, to_string(A).size(), to_string(SL).size()) {
ll p10 = 1;
fr(j, i) { p10 *= 10; }
ll T = min(p10 - 1, SL) - A;
T = T >= 0 ? T / B + 1 : 0;
ll C = 1, D = 0, E = 0, F = 0, k = 0;
for (int j = 0; T >> j; ++j) {
ll P = pow(p10, 1ll << j, M);
if (T >> j & 1) {
E = (E * P % M + D + C * k % M) % M;
F = (F * P % M + C) % M;
k = (k + (1ll << j)) % M;
}
D = (D * (P + 1) % M + C * pow(2, j, M) % M) % M;
C = C * (P + 1) % M;
}
E = (B % M * E % M + A % M * F % M) % M;
z = (z * pow(p10, T, M) % M + E) % M;
A = A + T * B;
}
print(z);
return 0;
}
| [
"call.remove"
] | 829,673 | 829,674 | u283869437 | cpp |
p03016 | #include <bits/stdc++.h>
#define dbug(x) cout << #x << "=" << x << endl
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
ll a, b, L, mod, mi[100], tmp, lst, k;
ll cnt[20], sum[20];
ll s1[100], s2[100];
ll ans;
int main() {
// freopen("1.txt","r",stdin);
read(L);
read(a);
read(b);
read(mod);
ll l, r, res, mid, x, y, t1, t2;
tmp = 1;
lst = -1;
for (int i = 1; i <= 18; i++) {
l = lst, r = L - 1;
tmp *= 10;
while (l <= r) {
mid = (l + r) / 2;
if (a + mid * b < tmp)
res = mid, l = mid + 1;
else
r = mid - 1;
}
k = res - lst;
if (k < 0)
continue;
lst = res;
mi[0] = tmp % mod;
s1[0] = 1;
s2[0] = 0;
for (int j = 1; j <= 62; j++) {
mi[j] = mi[j - 1] * mi[j - 1] % mod;
s1[j] = (mi[j - 1] + 1) * s1[j - 1] % mod;
s2[j] = (mi[j - 1] + 1) * s2[j - 1] % mod +
(1LL << (j - 1)) % mod * s1[j - 1] % mod * mi[j - 1] % mod;
s2[j] %= mod;
}
cnt[i] = 1;
x = 0, y = 0;
t1 = 1, t2 = 0;
for (int j = 62; j >= 0; j--)
if (k & (1LL << j)) {
x += s1[j] * t1 % mod;
x %= mod;
y += (s2[j] + s1[j] * t2 % mod) * t1 % mod;
y %= mod;
t1 = t1 * mi[j] % mod;
t2 = (t2 + (1LL << j)) % mod;
cnt[i] = cnt[i] * mi[j] % mod;
}
sum[i] = (a + b * res) % mod * x % mod - b % mod * y % mod;
sum[i] = (sum[i] % mod + mod) % mod;
}
tmp = 1;
for (int i = 18; i >= 1; i--) {
ans += sum[i] * tmp % mod;
ans %= mod;
tmp = tmp * cnt[i] % mod;
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define dbug(x) cout << #x << "=" << x << endl
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
ll a, b, L, mod, mi[100], tmp, lst, k;
ll cnt[20], sum[20];
ll s1[100], s2[100];
ll ans;
int main() {
// freopen("1.txt","r",stdin);
read(L);
read(a);
read(b);
read(mod);
ll l, r, res, mid, x, y, t1, t2;
tmp = 1;
lst = -1;
for (int i = 1; i <= 18; i++) {
l = lst, r = L - 1;
tmp *= 10;
res = lst - 1;
while (l <= r) {
mid = (l + r) / 2;
if (a + mid * b < tmp)
res = mid, l = mid + 1;
else
r = mid - 1;
}
k = res - lst;
if (k < 0)
continue;
lst = res;
mi[0] = tmp % mod;
s1[0] = 1;
s2[0] = 0;
for (int j = 1; j <= 62; j++) {
mi[j] = mi[j - 1] * mi[j - 1] % mod;
s1[j] = (mi[j - 1] + 1) * s1[j - 1] % mod;
s2[j] = (mi[j - 1] + 1) * s2[j - 1] % mod +
(1LL << (j - 1)) % mod * s1[j - 1] % mod * mi[j - 1] % mod;
s2[j] %= mod;
}
cnt[i] = 1;
x = 0, y = 0;
t1 = 1, t2 = 0;
for (int j = 62; j >= 0; j--)
if (k & (1LL << j)) {
x += s1[j] * t1 % mod;
x %= mod;
y += (s2[j] + s1[j] * t2 % mod) * t1 % mod;
y %= mod;
t1 = t1 * mi[j] % mod;
t2 = (t2 + (1LL << j)) % mod;
cnt[i] = cnt[i] * mi[j] % mod;
}
sum[i] = (a + b * res) % mod * x % mod - b % mod * y % mod;
sum[i] = (sum[i] % mod + mod) % mod;
}
tmp = 1;
for (int i = 18; i >= 1; i--) {
ans += sum[i] * tmp % mod;
ans %= mod;
tmp = tmp * cnt[i] % mod;
}
printf("%lld\n", ans);
return 0;
} | [
"assignment.add"
] | 829,693 | 829,694 | u880862257 | cpp |
p03016 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
ll c[20], d[20] = {1ll}, r[20] = {1ll}, m, ans[1][3], mt[3][3], tmp[3][3];
void mul1() {
int i, j, k;
for (i = 0; i < 1; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 3; ++k) {
tmp[i][j] += (ans[i][k] * mt[k][j]) % m;
tmp[i][j] %= m;
}
}
}
for (i = 0; i < 1; ++i) {
for (j = 0; j < 3; ++j) {
ans[i][j] = tmp[i][j];
tmp[i][j] = 0ll;
}
}
}
void mul2() {
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 3; ++k) {
tmp[i][j] += (mt[i][k] * mt[k][j]) % m;
tmp[i][j] %= m;
}
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
mt[i][j] = tmp[i][j];
tmp[i][j] = 0ll;
}
}
}
int main(void) {
int i;
ll l, a, b, q;
cin >> l >> a >> b >> m;
ans[0][0] = 0ll;
ans[0][1] = a;
ans[0][2] = 1ll;
for (i = 0; i < 18; ++i) {
d[i + 1] = d[i] * 10;
r[i + 1] = r[i] * 10;
r[i + 1] %= m;
}
c[0] = -1ll;
for (i = 1; i <= 18; ++i) {
--d[i];
if (a > d[i]) {
c[i] = -1ll;
continue;
} else {
c[i] = min((d[i] - a) / b, l - 1);
}
}
for (i = 1; i <= 18; ++i) {
if (a > d[i]) {
continue;
}
q = c[i] - c[i - 1];
mt[0][0] = r[i];
mt[0][1] = 0ll;
mt[0][2] = 0ll;
mt[1][0] = 1ll;
mt[1][1] = 1ll;
mt[1][2] = 0ll;
mt[2][0] = 0ll;
mt[2][1] = b;
mt[2][2] = 1ll;
while (q) {
if (q & 1) {
mul1();
}
mul2();
q /= 2;
}
}
cout << ans[0][0] << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
ll c[20], d[20] = {1ll}, r[20] = {1ll}, m, ans[1][3], mt[3][3], tmp[3][3];
void mul1() {
int i, j, k;
for (i = 0; i < 1; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 3; ++k) {
tmp[i][j] += (ans[i][k] * mt[k][j]) % m;
tmp[i][j] %= m;
}
}
}
for (i = 0; i < 1; ++i) {
for (j = 0; j < 3; ++j) {
ans[i][j] = tmp[i][j];
tmp[i][j] = 0ll;
}
}
}
void mul2() {
int i, j, k;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 3; ++k) {
tmp[i][j] += (mt[i][k] * mt[k][j]) % m;
tmp[i][j] %= m;
}
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
mt[i][j] = tmp[i][j];
tmp[i][j] = 0ll;
}
}
}
int main(void) {
int i;
ll l, a, b, q;
cin >> l >> a >> b >> m;
ans[0][0] = 0ll;
ans[0][1] = a % m;
ans[0][2] = 1ll;
for (i = 0; i < 18; ++i) {
d[i + 1] = d[i] * 10;
r[i + 1] = r[i] * 10;
r[i + 1] %= m;
}
c[0] = -1ll;
for (i = 1; i <= 18; ++i) {
--d[i];
if (a > d[i]) {
c[i] = -1ll;
continue;
} else {
c[i] = min((d[i] - a) / b, l - 1);
}
}
for (i = 1; i <= 18; ++i) {
if (a > d[i]) {
continue;
}
q = c[i] - c[i - 1];
mt[0][0] = r[i];
mt[0][1] = 0ll;
mt[0][2] = 0ll;
mt[1][0] = 1ll;
mt[1][1] = 1ll;
mt[1][2] = 0ll;
mt[2][0] = 0ll;
mt[2][1] = b % m;
mt[2][2] = 1ll;
while (q) {
if (q & 1) {
mul1();
}
mul2();
q /= 2;
}
}
cout << ans[0][0] << endl;
return 0;
}
| [
"assignment.change"
] | 829,701 | 829,702 | u548624367 | cpp |
p03016 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define cINF ((1ull << 62) - 1)
#define cINFINT ((1 << 30) - 1)
template <typename T> class Matrix {
public:
explicit Matrix(size_t row_size, size_t col_size) {
mElement.assign(row_size, vector<T>());
REP(i, row_size) mElement[i].assign(col_size, T(0));
}
const vector<T> &operator[](size_t row) const { return mElement[row]; }
vector<T> &operator[](size_t row) { return mElement[row]; }
const size_t rowSize() const { return mElement.size(); }
const size_t colSize() const { return mElement[0].size(); }
protected:
vector<vector<T>> mElement;
};
template <typename T> class SquareMatrix : public Matrix<T> {
public:
explicit SquareMatrix(size_t size) : Matrix<T>(size, size) {}
void identity() {
REP(i, this->rowSize())
REP(j, this->colSize())(*this)[i][j] = i == j ? T(1) : T(0);
}
SquareMatrix<T> operator*(const SquareMatrix &rhs) const {
size_t size = min(this->colSize(), rhs.colSize());
SquareMatrix<T> ret(size);
REP(i, size)
REP(k, size)
REP(j, size) { ret[i][j] = ret[i][j] + (*this)[i][k] * rhs[k][j]; }
return ret;
}
SquareMatrix<T> operator^(size_t n) const {
SquareMatrix base = *this;
SquareMatrix ret(this->rowSize());
ret.identity();
while (n > 0) {
if (n & 1)
ret = ret * base;
base = base * base;
n >>= 1;
}
return ret;
}
SquareMatrix<T> mul(const SquareMatrix &rhs, ll mod) const {
size_t size = min(this->colSize(), rhs.colSize());
SquareMatrix<T> ret(size);
REP(i, size)
REP(k, size)
REP(j, size) {
ret[i][j] = (ret[i][j] + (*this)[i][k] * rhs[k][j] % mod) % mod;
}
return ret;
}
SquareMatrix<T> pow(size_t n, ll mod) const {
SquareMatrix base = *this;
SquareMatrix ret(this->rowSize());
ret.identity();
while (n > 0) {
if (n & 1)
ret = ret.mul(base, mod);
base = base.mul(base, mod);
n >>= 1;
}
return ret;
}
};
template <typename T> void calcPow_mod(T x, vector<T> &powArray, T mod) {
REP(i, powArray.size()) if (i != 0) powArray[i] = powArray[i - 1] * x % mod;
}
int main() {
ll l, a, b, mod;
cin >> l >> a >> b >> mod;
vector<ll> powAry(19, 1);
calcPow_mod(10ll, powAry, mod);
auto add = [&mod](ll a, ll b) { return (a + b) % mod; };
auto mul = [&mod](ll a, ll b) { return a * b % mod; };
auto solve = [&mod, &b, &powAry, add, mul](ll &ans, ll start, ll end, ll d) {
ll n = (end - start) / b + 1;
SquareMatrix<ll> mtx(3);
mtx[0][0] = powAry[d] % mod;
mtx[0][1] = 1;
mtx[0][2] = 0;
mtx[1][0] = 0;
mtx[1][1] = 1;
mtx[1][2] = b % mod;
mtx[2][0] = 0;
mtx[2][1] = 0;
mtx[2][2] = 1;
mtx = mtx.pow(n, mod);
ans = add(mul(ans, mtx[0][0]), mul(start % mod, mtx[0][1]));
ans = add(ans, mtx[0][2]);
};
ll start = a;
ll end = a + b * (l - 1);
ll ans = 0;
REP(i, 19) if (i != 0) if (start < powAry[i]) {
ll dend = (powAry[i] - 1 - start) / b * b + start;
if (dend > end)
dend = end;
solve(ans, start, dend, i);
if (dend == end)
break;
start = dend + b;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define cINF ((1ull << 62) - 1)
#define cINFINT ((1 << 30) - 1)
template <typename T> class Matrix {
public:
explicit Matrix(size_t row_size, size_t col_size) {
mElement.assign(row_size, vector<T>());
REP(i, row_size) mElement[i].assign(col_size, T(0));
}
const vector<T> &operator[](size_t row) const { return mElement[row]; }
vector<T> &operator[](size_t row) { return mElement[row]; }
const size_t rowSize() const { return mElement.size(); }
const size_t colSize() const { return mElement[0].size(); }
protected:
vector<vector<T>> mElement;
};
template <typename T> class SquareMatrix : public Matrix<T> {
public:
explicit SquareMatrix(size_t size) : Matrix<T>(size, size) {}
void identity() {
REP(i, this->rowSize())
REP(j, this->colSize())(*this)[i][j] = i == j ? T(1) : T(0);
}
SquareMatrix<T> operator*(const SquareMatrix &rhs) const {
size_t size = min(this->colSize(), rhs.colSize());
SquareMatrix<T> ret(size);
REP(i, size)
REP(k, size)
REP(j, size) { ret[i][j] = ret[i][j] + (*this)[i][k] * rhs[k][j]; }
return ret;
}
SquareMatrix<T> operator^(size_t n) const {
SquareMatrix base = *this;
SquareMatrix ret(this->rowSize());
ret.identity();
while (n > 0) {
if (n & 1)
ret = ret * base;
base = base * base;
n >>= 1;
}
return ret;
}
SquareMatrix<T> mul(const SquareMatrix &rhs, ll mod) const {
size_t size = min(this->colSize(), rhs.colSize());
SquareMatrix<T> ret(size);
REP(i, size)
REP(k, size)
REP(j, size) {
ret[i][j] = (ret[i][j] + (*this)[i][k] * rhs[k][j] % mod) % mod;
}
return ret;
}
SquareMatrix<T> pow(size_t n, ll mod) const {
SquareMatrix base = *this;
SquareMatrix ret(this->rowSize());
ret.identity();
while (n > 0) {
if (n & 1)
ret = ret.mul(base, mod);
base = base.mul(base, mod);
n >>= 1;
}
return ret;
}
};
template <typename T> void calcPow_mod(T x, vector<T> &powArray, T mod) {
REP(i, powArray.size()) if (i != 0) powArray[i] = powArray[i - 1] * x % mod;
}
int main() {
ll l, a, b, mod;
cin >> l >> a >> b >> mod;
vector<ll> powAry(19, 1);
calcPow_mod<ll>(10, powAry, cINF);
auto add = [&mod](ll a, ll b) { return (a + b) % mod; };
auto mul = [&mod](ll a, ll b) { return a * b % mod; };
auto solve = [&mod, &b, &powAry, add, mul](ll &ans, ll start, ll end, ll d) {
ll n = (end - start) / b + 1;
SquareMatrix<ll> mtx(3);
mtx[0][0] = powAry[d] % mod;
mtx[0][1] = 1;
mtx[0][2] = 0;
mtx[1][0] = 0;
mtx[1][1] = 1;
mtx[1][2] = b % mod;
mtx[2][0] = 0;
mtx[2][1] = 0;
mtx[2][2] = 1;
mtx = mtx.pow(n, mod);
ans = add(mul(ans, mtx[0][0]), mul(start % mod, mtx[0][1]));
ans = add(ans, mtx[0][2]);
};
ll start = a;
ll end = a + b * (l - 1);
ll ans = 0;
REP(i, 19) if (i != 0) if (start < powAry[i]) {
ll dend = (powAry[i] - 1 - start) / b * b + start;
if (dend > end)
dend = end;
solve(ans, start, dend, i);
if (dend == end)
break;
start = dend + b;
}
cout << ans << endl;
return 0;
} | [
"call.arguments.change",
"identifier.change"
] | 829,705 | 829,706 | u627427672 | cpp |
p03016 | #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(const mat &A, const mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] * B[k][j]) % mod;
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA}, {tmpB}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A - 1) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Int ans = Q[0][0];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(const mat &A, const mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] * B[k][j]) % mod;
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA % mod}, {tmpB % mod}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A - 1) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Int ans = Q[0][0];
cout << ans << endl;
return 0;
}
| [
"assignment.change"
] | 829,707 | 829,708 | u278868910 | cpp |
p03016 | #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(const mat &A, const mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] * B[k][j]) % mod;
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA}, {tmpB}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A - 1) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Int ans = Q[0][0];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(const mat &A, const mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] % mod) * (B[k][j] % mod) % mod;
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA}, {tmpB}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A - 1) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Int ans = Q[0][0];
cout << ans << endl;
return 0;
}
| [
"assignment.change"
] | 829,707 | 829,709 | u278868910 | cpp |
p03016 | #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(const mat &A, const mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] * B[k][j]);
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA}, {tmpB}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Int ans = Q[0][0];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
o << "[";
for (T t : a)
o << (i++ ? ", " : "") << t;
o << "]";
return o;
}
// INSERT ABOVE HERE
class Integer {
public:
string val;
Integer() : val("0") {}
Integer(string num, bool reversed = 0) {
if (!reversed)
R(num);
val = num;
}
Integer(Int num) {
val = to_string(num);
R(val);
}
void R(string &a) { reverse(a.begin(), a.end()); }
bool neg(const string &a) const { return a.back() == '-'; }
char &operator[](Int i) {
assert(i < (Int)val.size());
return val[i];
}
bool operator==(Integer b) {
R(b.val);
return *this == b.val;
}
bool operator==(string b) {
R(b);
return val == b;
}
template <class T> bool operator==(T b) { return *this == Integer(b); }
bool operator!=(Integer b) {
R(b.val);
return *this != b.val;
}
bool operator!=(string b) {
R(b);
return !(val == b);
}
template <class T> bool operator!=(T b) { return *this != Integer(b); }
bool operator>=(Integer b) {
R(b.val);
return *this >= b.val;
}
bool operator>=(string b) { return !(*this < b); }
template <class T> bool operator>=(T b) { return *this >= Integer(b); }
bool operator>(Integer b) {
R(b.val);
return *this > b.val;
}
bool operator>(string b) { return *this >= b && *this != b; }
template <class T> bool operator>(T b) { return *this > Integer(b); }
bool operator<=(Integer b) {
R(b.val);
return *this <= b.val;
}
bool operator<=(string b) { return *this < b || *this == b; }
template <class T> bool operator<=(T b) { return *this <= Integer(b); }
bool operator<(Integer b) {
R(b.val);
return *this < b.val;
}
template <class T> bool operator<(T b) { return *this < Integer(b); }
bool operator<(string b) {
R(b);
const string &a = val;
if (neg(a) != neg(b))
return neg(a) ? 1 : 0;
if (a.size() != b.size())
return !neg(a) ? (a.size() < b.size()) : (a.size() > b.size());
for (Int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return !neg(a) ? a[i] < b[i] : a[i] > b[i];
return 0;
}
Integer operator+(string b) {
R(b);
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (Integer(a, 1) < Integer(b, 1))
swap(a, b), swap(fa, fb);
if (fa == fb) {
a += '0';
for (Int i = 0; i < (Int)a.size() - 1; i++) {
if (i < (Int)b.size())
a[i] += b[i] - '0';
a[i + 1] += (a[i] - '0') / 10;
a[i] = (a[i] - '0') % 10 + '0';
}
if (a.size() > 1 && a.back() == '0')
a.pop_back();
if ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
} else {
for (Int i = 0; i < (Int)a.size(); i++) {
if (i < (Int)b.size())
a[i] -= b[i] - '0';
if (a[i] - '0' < 0)
a[i] += 10, a[i + 1]--;
}
while ((Int)a.size() > 1 && a.back() == '0')
a.pop_back();
if (a != "0")
a += fa;
}
return Integer(a, 1);
}
Integer operator*(string b) {
R(b);
vector<Int> res;
string a = val;
string fa = neg(a) ? "-" : "";
string fb = neg(b) ? "-" : "";
if (neg(a))
a.pop_back();
if (neg(b))
b.pop_back();
if (a.size() < b.size())
swap(a, b), swap(fa, fb);
if (a == "0" || b == "0")
return Integer("0");
for (Int j = 0; j < (Int)b.size(); j++)
for (Int i = 0; i < (Int)a.size(); i++) {
if (i + j >= (Int)res.size())
res.push_back(0);
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
for (Int i = 0; i < (Int)res.size(); i++) {
if (res[i] / 10 == 0)
continue;
if (i + 1 >= (Int)res.size())
res.push_back(0);
res[i + 1] += res[i] / 10, res[i] = res[i] % 10;
}
string sres;
for (Int i : res)
sres += char(i + '0');
if (fa != fb)
sres += '-';
return Integer(sres, 1);
}
Integer div(string b, Int flg) {
assert(b != "0");
string a = val;
string fa = neg(a) ? "-" : "";
string fb = b[0] == '-' ? "-" : "";
if (neg(a))
a.pop_back();
if (b[0] == '-')
b.erase(b.begin());
Integer mod("0");
string d = "0";
for (Int i = (Int)a.size() - 1; i >= 0; i--) {
mod = mod * 10 + (a[i] - '0');
while (mod >= b)
mod -= b, d.back() += 1;
if (i && d != "0")
d += '0';
}
if (flg == 0 && d != "0" && (fa != fb))
d = "-" + d;
if (flg == 1 && mod != "0" && (fa == "-"))
mod *= -1;
return flg == 0 ? d : mod;
}
Integer operator+(Integer b) {
R(b.val);
return *this + b.val;
}
template <class T> Integer operator+(T b) { return *this + Integer(b); }
Integer operator*(Integer b) {
R(b.val);
return *this * b.val;
}
template <class T> Integer operator*(T b) { return *this * Integer(b); }
Integer operator-(string b) {
b = (b[0] == '-') ? b.substr(1) : "-" + b;
return *this + b;
}
Integer operator-(Integer b) {
R(b.val);
return *this - b.val;
}
template <class T> Integer operator-(T b) { return *this - Integer(b); }
Integer operator/(string b) { return div(b, 0); }
Integer operator/(Integer b) {
R(b.val);
return div(b.val, 0);
}
template <class T> Integer operator/(T b) { return *this / Integer(b); }
Integer operator%(string b) { return div(b, 1); }
Integer operator%(Integer b) {
R(b.val);
return div(b.val, 1);
}
template <class T> Integer operator%(T b) { return *this % Integer(b); }
Integer operator+=(Integer b) { return *this = *this + b; }
Integer operator+=(string b) { return *this = *this + b; }
template <class T> Integer operator+=(T b) { return *this += Integer(b); }
Integer operator-=(Integer b) { return *this = *this - b; }
Integer operator-=(string b) { return *this = *this - b; }
template <class T> Integer operator-=(T b) { return *this -= Integer(b); }
Integer operator*=(Integer b) { return *this = *this * b; }
Integer operator*=(string b) { return *this = *this * b; }
template <class T> Integer operator*=(T b) { return *this *= Integer(b); }
Integer operator/=(string b) { return *this = *this / b; }
Integer operator/=(Integer b) { return *this = *this / b; }
template <class T> Integer operator/=(T b) { return *this /= Integer(b); }
Integer operator%=(string b) { return *this = *this % b; }
Integer operator%=(Integer b) { return *this = *this % b; }
template <class T> Integer operator%=(T b) { return *this %= Integer(b); }
Integer operator++() { return *this += 1; }
Integer operator--() { return *this -= 1; }
#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
Integer operator++(int) {
Integer tmp = *this;
*this += 1;
return tmp;
}
Integer operator--(int) {
Integer tmp = *this;
*this -= 1;
return tmp;
}
#ifdef eraseIntegerDefine
#define Int long long
#endif
friend ostream &operator<<(ostream &os, const Integer a) {
for (Int i = (Int)a.val.size() - 1; i >= 0; i--)
os << a.val[i];
return os;
}
friend istream &operator>>(istream &is, Integer &a) {
string num;
is >> num;
a = Integer(num);
return is;
}
friend string to_string(Integer a) {
reverse(a.val.begin(), a.val.end());
return a.val;
}
};
Int mod;
typedef vector<Integer> vec;
typedef vector<vec> mat;
/*ๆใ็ฎ*/
mat mult(mat &A, mat &B) {
assert(A[0].size() == B.size());
Int n = A.size(), m = B.size(), l = B[0].size();
mat C(A.size(), vec(l, 0));
for (Int i = 0; i < n; i++)
for (Int j = 0; j < l; j++)
for (Int k = 0; k < m; k++) {
C[i][j] += (A[i][k] * B[k][j]);
C[i][j] %= mod;
}
return C;
}
mat pow(mat A, Integer y) {
mat res(A.size(), vec(A.size()));
for (Int i = 0; i < (Int)A.size(); i++)
res[i][i] = 1;
while (y != 0) {
if (y % 2 == 1)
res = mult(res, A);
A = mult(A, A);
y /= 2;
}
return res;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int L, tmpA, tmpB, M;
cin >> L >> tmpA >> tmpB >> M;
Integer A = tmpA;
Integer B = tmpB;
mod = M;
Integer l = 0;
Integer Limit = 1;
Int limit = 1;
mat Q = {{0}, {tmpA}, {tmpB}};
while (l < L) {
Limit = Limit * 10;
limit = limit * 10 % mod;
// A + B * r < limit
// r < (limit - A) / B;
Integer num = (Limit - A - 1) / B + 1;
if (A >= Limit || num <= 0)
continue;
Integer r = l + num;
if (r > L)
r = L;
mat P = {{limit, 1, 0}, {0, 1, 1}, {0, 0, 1}};
P = pow(P, r - l);
Q = mult(P, Q);
// pr(l, r, Limit, P, Q, A);
A = A + B * (r - l);
l = r;
}
Integer ans = Q[0][0];
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 829,712 | 829,711 | u278868910 | cpp |
p03016 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = long long;
constexpr int MAXDC = 19;
ll mod; // to be scanf'ed
ll modexp(ll b, ull e) {
return (e == 0 ? 1 : (e % 2 == 1 ? b : 1) * modexp(b * b % mod, e / 2) % mod);
}
int digCount(ll x) {
if (x <= 9)
return 1;
else
return 1 + digCount(x / 10);
}
// MIND = min index with needed digits
ll findMIND(ll a, ll b, int ndc, ll maxFind) {
if (digCount(a + b * (maxFind - 1)) < ndc)
return -1;
else {
ll lo = 0;
ll hi = maxFind - 1;
while (lo < hi) {
ll mid = (lo + hi) / 2;
if (digCount(a + mid * b) >= ndc)
hi = mid;
else
lo = mid + 1;
}
if (digCount(a + lo * b) == ndc)
return lo;
else
return -1;
}
}
// computes 1 + r + r2 + ... + r^(ct - 1) following the modulo
ll geomSum(ll r, ll ct) {
if (ct == 1)
return 1;
else if (ct % 2 == 1)
return (1 + r * geomSum(r, ct - 1) % mod) % mod;
else {
// 1 + r + r2 + ... + r^(ct/2 - 1)
// and r^(ct/2) + ... + r^(ct - 1) = r^(ct/2) * (1 + r + r2 + ... + r^(ct/2
// - 1))
return (modexp(r, ct / 2) + 1) * geomSum(r, ct / 2) % mod;
}
}
/*
// computes
// s + (s - dec) * base + (s - 2dec) * base^2 + ... + (s - tc*dec) * base^(tc-1)
if tc = 0,
this is just s
the weights look like
arithGeoSum(9, 4, 2, base)
********* i = 0 => the larger
******* i = 1
***** i = 2 => the smaller arith geo starts at this term
*** i = 3
the result is 9 + 7b + 5b^2 + 3b^3
i split this as 5 + 3b + (4 + 4b) + b^2(5 + 3b)
we have to compute the a offset and the g offset
the a offset is the
****
****
so it has a width of tc/2 * dec, so it's all
tc/2 * dec * (1 + base + ... + base^(tc/2 - 1))
the g offset is basically that the smaller AG appears multiplied by base^(tc/2)
*/
ll arithGeoSum(ll s, ll tc, ll dec, ll base) {
ll ans;
if (tc == 1)
ans = s;
else if (tc % 2 == 1) {
ll lastTerm = (s % mod - ((tc - 1) % mod) * (dec % mod) % mod) % mod *
modexp(base, tc - 1) % mod;
ans = (arithGeoSum(s, tc - 1, dec, base) + lastTerm) % mod;
} else {
// consider (s - tc/2 * dec) * base^(tc/2 + 1)
ll smallerAG = arithGeoSum(s - tc / 2 * dec, tc / 2, dec, base);
ll arithOffset = (tc / 2 * dec % mod * geomSum(base, tc / 2)) % mod;
ans = (arithOffset + (modexp(base, tc / 2) + 1) * smallerAG) % mod;
}
// printf("ags %lld %lld %lld %lld = %lld\n", s, tc, dec, base, ans % mod);
return ans % mod;
}
signed main() {
ll mf, a, b;
scanf("%lld %lld %lld %lld", &mf, &a, &b, &mod);
vector<pair<ll, int>> newDCStart; // (index, dc)
for (int i = 1; i < MAXDC; ++i) {
ll dspos = findMIND(a, b, i, mf - 1);
if (dspos != -1) {
newDCStart.emplace_back(dspos, i);
}
}
vector<pair<ll, ll>> dcranges(MAXDC, {-1, -1});
for (int i = 0; i < newDCStart.size(); ++i) {
if (i + 1 == newDCStart.size()) // this is the last one
dcranges[newDCStart[i].second] = {newDCStart[i].first, mf - 1};
else {
dcranges[newDCStart[i].second] = {newDCStart[i].first,
newDCStart[i + 1].first - 1};
}
}
// for (int i = 1; i < MAXDC; ++i) {
// printf("%d %lld %lld\n", i, dcranges[i].first, dcranges[i].second);
// }
vector<ll> offsetMul(MAXDC);
ll curOffset = 1;
for (ll i = MAXDC - 1; i >= 1; --i) {
if (dcranges[i].first != -1) {
offsetMul[i] = curOffset;
curOffset =
(curOffset *
modexp(modexp(10, dcranges[i].second - dcranges[i].first + 1), i) %
mod);
}
}
// for (int i = 1; i < MAXDC; ++i) {
// printf("%lld\n", rowStartsAt[i]);
// }
ll ans = 0;
for (int i = 1; i < MAXDC; ++i) {
if (dcranges[i].first != -1) {
ll rstart = a + dcranges[i].second * b;
// the dec is b, the base is 10, the tc is the sequence length
ll crcontrib = arithGeoSum(
rstart, dcranges[i].second - dcranges[i].first + 1, b, modexp(10, i));
// printf("%d has crcontrib %lld\n", i, crcontrib);
ans = (ans + crcontrib * offsetMul[i] % mod) % mod;
}
}
printf("%lld\n", (ans + mod) % mod);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = long long;
constexpr int MAXDC = 19;
ll mod; // to be scanf'ed
ll modexp(ll b, ull e) {
return (e == 0 ? 1 : (e % 2 == 1 ? b : 1) * modexp(b * b % mod, e / 2) % mod);
}
int digCount(ll x) {
if (x <= 9)
return 1;
else
return 1 + digCount(x / 10);
}
// MIND = min index with needed digits
ll findMIND(ll a, ll b, int ndc, ll maxFind) {
if (digCount(a + b * (maxFind - 1)) < ndc)
return -1;
else {
ll lo = 0;
ll hi = maxFind - 1;
while (lo < hi) {
ll mid = (lo + hi) / 2;
if (digCount(a + mid * b) >= ndc)
hi = mid;
else
lo = mid + 1;
}
if (digCount(a + lo * b) == ndc)
return lo;
else
return -1;
}
}
// computes 1 + r + r2 + ... + r^(ct - 1) following the modulo
ll geomSum(ll r, ll ct) {
if (ct == 1)
return 1;
else if (ct % 2 == 1)
return (1 + r * geomSum(r, ct - 1) % mod) % mod;
else {
// 1 + r + r2 + ... + r^(ct/2 - 1)
// and r^(ct/2) + ... + r^(ct - 1) = r^(ct/2) * (1 + r + r2 + ... + r^(ct/2
// - 1))
return (modexp(r, ct / 2) + 1) * geomSum(r, ct / 2) % mod;
}
}
/*
// computes
// s + (s - dec) * base + (s - 2dec) * base^2 + ... + (s - tc*dec) * base^(tc-1)
if tc = 0,
this is just s
the weights look like
arithGeoSum(9, 4, 2, base)
********* i = 0 => the larger
******* i = 1
***** i = 2 => the smaller arith geo starts at this term
*** i = 3
the result is 9 + 7b + 5b^2 + 3b^3
i split this as 5 + 3b + (4 + 4b) + b^2(5 + 3b)
we have to compute the a offset and the g offset
the a offset is the
****
****
so it has a width of tc/2 * dec, so it's all
tc/2 * dec * (1 + base + ... + base^(tc/2 - 1))
the g offset is basically that the smaller AG appears multiplied by base^(tc/2)
*/
ll arithGeoSum(ll s, ll tc, ll dec, ll base) {
ll ans;
if (tc == 1)
ans = s;
else if (tc % 2 == 1) {
ll lastTerm = (s % mod - ((tc - 1) % mod) * (dec % mod) % mod) % mod *
modexp(base, tc - 1) % mod;
ans = (arithGeoSum(s, tc - 1, dec, base) + lastTerm) % mod;
} else {
// consider (s - tc/2 * dec) * base^(tc/2 + 1)
ll smallerAG = arithGeoSum(s - tc / 2 * dec, tc / 2, dec, base);
ll arithOffset = (tc / 2 * dec % mod * geomSum(base, tc / 2)) % mod;
ans = (arithOffset + (modexp(base, tc / 2) + 1) * smallerAG) % mod;
}
// printf("ags %lld %lld %lld %lld = %lld\n", s, tc, dec, base, ans % mod);
return ans % mod;
}
signed main() {
ll mf, a, b;
scanf("%lld %lld %lld %lld", &mf, &a, &b, &mod);
vector<pair<ll, int>> newDCStart; // (index, dc)
for (int i = 1; i < MAXDC; ++i) {
ll dspos = findMIND(a, b, i, mf);
if (dspos != -1) {
newDCStart.emplace_back(dspos, i);
}
}
vector<pair<ll, ll>> dcranges(MAXDC, {-1, -1});
for (int i = 0; i < newDCStart.size(); ++i) {
if (i + 1 == newDCStart.size()) // this is the last one
dcranges[newDCStart[i].second] = {newDCStart[i].first, mf - 1};
else {
dcranges[newDCStart[i].second] = {newDCStart[i].first,
newDCStart[i + 1].first - 1};
}
}
// for (int i = 1; i < MAXDC; ++i) {
// printf("%d %lld %lld\n", i, dcranges[i].first, dcranges[i].second);
// }
vector<ll> offsetMul(MAXDC);
ll curOffset = 1;
for (ll i = MAXDC - 1; i >= 1; --i) {
if (dcranges[i].first != -1) {
offsetMul[i] = curOffset;
curOffset =
(curOffset *
modexp(modexp(10, dcranges[i].second - dcranges[i].first + 1), i) %
mod);
}
}
// for (int i = 1; i < MAXDC; ++i) {
// printf("%lld\n", rowStartsAt[i]);
// }
ll ans = 0;
for (int i = 1; i < MAXDC; ++i) {
if (dcranges[i].first != -1) {
ll rstart = a + dcranges[i].second * b;
// the dec is b, the base is 10, the tc is the sequence length
ll crcontrib = arithGeoSum(
rstart, dcranges[i].second - dcranges[i].first + 1, b, modexp(10, i));
// printf("%d has crcontrib %lld\n", i, crcontrib);
ans = (ans + crcontrib * offsetMul[i] % mod) % mod;
}
}
printf("%lld\n", (ans + mod) % mod);
return 0;
} | [
"expression.operation.binary.remove"
] | 829,715 | 829,716 | u904217313 | cpp |
p03017 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
string S;
cin >> S;
bool flag1 = 0;
for (int i = A - 1; i <= max(C, D) - 2; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No";
return 0;
}
}
if (C > D) {
for (int i = B - 2; i <= N - 2; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
flag1 = 1;
}
if (flag1 == 0)
cout << "No";
else
cout << "Yes";
} else
cout << "Yes";
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
string S;
cin >> S;
bool flag1 = 0;
for (int i = A - 1; i <= max(C, D) - 2; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No";
return 0;
}
}
if (C > D) {
for (int i = B - 2; i <= D - 2; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
flag1 = 1;
}
if (flag1 == 0)
cout << "No";
else
cout << "Yes";
} else
cout << "Yes";
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 829,728 | 829,729 | u328530240 | cpp |
p03017 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
string S;
cin >> S;
bool flag1 = 0;
for (int i = A - 1; i <= max(C, D) - 2; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No";
return 0;
}
}
if (C > D) {
for (int i = B - 1; i <= D - 1 - 2; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
flag1 = 1;
}
if (flag1 == 0)
cout << "No";
else
cout << "Yes";
} else
cout << "Yes";
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
string S;
cin >> S;
bool flag1 = 0;
for (int i = A - 1; i <= max(C, D) - 2; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No";
return 0;
}
}
if (C > D) {
for (int i = B - 2; i <= D - 2; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
flag1 = 1;
}
if (flag1 == 0)
cout << "No";
else
cout << "Yes";
} else
cout << "Yes";
return 0;
} | [
"literal.number.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 829,730 | 829,729 | u328530240 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
string s;
cin >> s;
a--;
b--;
c--;
d--;
if (s[c] == '#' || s[d] == '#')
return cout << "No", 0;
if (c == d)
return cout << "No", 0;
if (d > c) {
for (int i = a; i < d; i++) {
if (s[i] == '#' && s[i + 1] == '#')
return cout << "No", 0;
}
cout << "Yes\n";
} else if (d < c) {
for (int i = a; i < c; i++) {
if (s[i] == '#' && s[i + 1] == '#')
return cout << "No", 0;
}
for (int i = b - 1; i < d - 1; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
return cout << "Yes", 0;
}
}
cout << "No";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
string s;
cin >> s;
a--;
b--;
c--;
d--;
if (s[c] == '#' || s[d] == '#')
return cout << "No", 0;
if (c == d)
return cout << "No", 0;
if (d > c) {
for (int i = a; i < d; i++) {
if (s[i] == '#' && s[i + 1] == '#')
return cout << "No", 0;
}
cout << "Yes\n";
} else if (d < c) {
for (int i = a; i < c; i++) {
if (s[i] == '#' && s[i + 1] == '#')
return cout << "No", 0;
}
for (int i = b - 1; i < d; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
return cout << "Yes", 0;
}
}
cout << "No";
}
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 829,731 | 829,732 | u764378605 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
bool f1(ll a, ll b) {
for (ll i = a; i < b; ++i) {
if (s[i] == '#' && s[i + 1] == '#')
return false;
}
return true;
}
bool f2(ll a, ll b) {
for (ll i = a + 1; i < b; ++i) {
if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
return true;
}
return false;
}
int main() {
ll n, a, b, c, d;
cin >> n >> a >> b >> c >> d >> s;
--a;
--b;
--c;
--d;
bool flag;
if (c < d) {
flag = f1(a, d);
} else {
flag = f1(a, c) && f2(b, d);
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
bool f1(ll a, ll b) {
for (ll i = a; i < b; ++i) {
if (s[i] == '#' && s[i + 1] == '#')
return false;
}
return true;
}
bool f2(ll a, ll b) {
for (ll i = a; i <= b; ++i) {
if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
return true;
}
return false;
}
int main() {
ll n, a, b, c, d;
cin >> n >> a >> b >> c >> d >> s;
--a;
--b;
--c;
--d;
bool flag;
if (c < d) {
flag = f1(a, d);
} else {
flag = f1(a, c) && f2(b, d);
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 829,736 | 829,737 | u698760125 | cpp |
p03017 | #include <bits/stdc++.h>
//#define int long long
using namespace std;
string s;
bool chk_block(int a, int b) {
for (int i = a; i < b - 1; ++i) {
if (s[i] == '#' && s[i + 1] == '#')
return false;
}
return true;
}
bool chk_jump(int a, int b) {
for (int i = a; i < b; ++i) {
if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
return true;
}
return false;
}
signed main() {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
--a;
--b;
--c;
--d;
cin >> s;
bool ans;
if (c < d)
ans = chk_block(a, d);
else
ans = chk_block(a, c) && chk_jump(b, d);
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
//#define int long long
using namespace std;
string s;
bool chk_block(int a, int b) {
for (int i = a; i <= b - 1; ++i) {
if (s[i] == '#' && s[i + 1] == '#')
return false;
}
return true;
}
bool chk_jump(int a, int b) {
for (int i = a; i <= b; ++i) {
if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
return true;
}
return false;
}
signed main() {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
--a;
--b;
--c;
--d;
cin >> s;
bool ans;
if (c < d)
ans = chk_block(a, d);
else
ans = chk_block(a, c) && chk_jump(b, d);
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 829,738 | 829,739 | u698760125 | cpp |
p03017 | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B - 1, D + 2);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B - 1, D);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"expression.operation.binary.remove"
] | 829,742 | 829,741 | u605901675 | cpp |
p03017 | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B - 1, D + 1);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B - 1, D);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"expression.operation.binary.remove"
] | 829,743 | 829,741 | u605901675 | cpp |
p03017 | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B, D);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// ็นๅฎใฎๆๅญๅใๆฐใใ้ขๆฐ
size_t count(const string &str, const string &sub, const size_t ini = 0,
const size_t fin = string::npos) {
size_t pos = str.find(sub, ini);
size_t cnt = 0;
while (pos < fin) {
cnt += 1;
pos = str.find(sub, pos + sub.length());
}
return cnt;
}
int main() {
int N;
int A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
int c1, c2;
bool jdg = false;
if (C < D) {
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
if (c1 == 0 && c2 == 0) {
jdg = true;
}
} else {
int c3;
c1 = count(S, "##", A, C);
c2 = count(S, "##", B, D);
c3 = count(S, "...", B - 1, D);
if (c1 == 0 && c2 == 0 && c3 > 0) {
jdg = true;
}
}
if (jdg == true) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"assignment.change"
] | 829,744 | 829,741 | u605901675 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
return x / GCD(x, y) *
y; //ๅ
ใซๅฒใ็ฎใใใฆๆใใใใๆฐใๅฐใใใใฆๆใ็ฎใ่กใ
}
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
bool ans = true;
if (C < D) {
for (int i = A; i < D; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} else if (C > D) {
for (int i = A; i < C; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
for (int i = B; i < D - 1; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
return x / GCD(x, y) *
y; //ๅ
ใซๅฒใ็ฎใใใฆๆใใใใๆฐใๅฐใใใใฆๆใ็ฎใ่กใ
}
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
bool ans = true;
if (C < D) {
for (int i = A; i < D; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} else if (C > D) {
for (int i = A; i < C; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
for (int i = B - 1; i < D; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
return 0;
}
| [
"control_flow.loop.for.initializer.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 829,748 | 829,749 | u109191542 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
return x / GCD(x, y) *
y; //ๅ
ใซๅฒใ็ฎใใใฆๆใใใใๆฐใๅฐใใใใฆๆใ็ฎใ่กใ
}
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
bool ans = true;
if (C < D) {
for (int i = A; i < D; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} else if (C > D) {
for (int i = A; i < C; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
for (int i = B; i < D - 1; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
return x / GCD(x, y) *
y; //ๅ
ใซๅฒใ็ฎใใใฆๆใใใใๆฐใๅฐใใใใฆๆใ็ฎใ่กใ
}
int main() {
int N, A, B, C, D;
cin >> N >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
string S;
cin >> S;
bool ans = true;
if (C < D) {
for (int i = A; i < D; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} else if (C > D) {
for (int i = A; i < C; i++) {
if (S[i] == '#' && S[i + 1] == '#') {
cout << "No" << endl;
return 0;
}
}
for (int i = B - 1; i < D; i++) {
if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
return 0;
}
| [
"control_flow.loop.for.initializer.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 829,750 | 829,749 | u109191542 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, a, b, c, d;
string s;
cin >> n >> a >> b >> c >> d >> s;
a--;
b--;
c--;
d--;
bool ans = true;
for (ll i = a; i <= max({c - 1, d - 1}); i++) {
if (s[i] == '#' && s[i + 1] == '#') {
ans = false;
}
}
if (c < d) {
if (ans) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
if (!ans) {
cout << "No" << endl;
return 0;
}
bool ans2 = false;
for (ll i = b - 1; i <= d - 2; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
ans2 = true;
}
}
if (ans2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, a, b, c, d;
string s;
cin >> n >> a >> b >> c >> d >> s;
a--;
b--;
c--;
d--;
bool ans = true;
for (ll i = a; i <= max({c - 1, d - 1}); i++) {
if (s[i] == '#' && s[i + 1] == '#') {
ans = false;
}
}
if (c < d) {
if (ans) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
if (!ans) {
cout << "No" << endl;
return 0;
}
bool ans2 = false;
for (ll i = b - 1; i <= d - 1; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
ans2 = true;
}
}
if (ans2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 829,755 | 829,756 | u659209756 | cpp |
p03017 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, a, b, c, d;
string s;
cin >> n >> a >> b >> c >> d >> s;
a--;
b--;
c--;
d--;
bool ans = true;
for (ll i = a; i <= max({c - 1, d - 1}); i++) {
if (s[i] == '#' && s[i + 1] == '#') {
ans = false;
}
}
if (c < d) {
if (ans) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
if (!ans) {
cout << "No" << endl;
return 0;
}
bool ans2 = false;
for (ll i = b; i <= d - 2; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
ans2 = true;
}
}
if (ans2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, a, b, c, d;
string s;
cin >> n >> a >> b >> c >> d >> s;
a--;
b--;
c--;
d--;
bool ans = true;
for (ll i = a; i <= max({c - 1, d - 1}); i++) {
if (s[i] == '#' && s[i + 1] == '#') {
ans = false;
}
}
if (c < d) {
if (ans) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
if (!ans) {
cout << "No" << endl;
return 0;
}
bool ans2 = false;
for (ll i = b - 1; i <= d - 1; i++) {
if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
ans2 = true;
}
}
if (ans2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"control_flow.loop.for.initializer.change",
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 829,757 | 829,756 | u659209756 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.