# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109002 |
2024-11-05T18:41:13 Z |
Kerim |
Mosaic (IOI24_mosaic) |
C++17 |
|
1000 ms |
108484 KB |
#include "bits/stdc++.h"
#define ll long long
#define pb push_back
#define pii pair<int, int>
using namespace std;
const int N = 4e5+5;
int cnt[N], arcalyk[4][N], tarhun[N][4];
const int M = 5005;
int dp[M][M];
int wow(int a, int b){
return (!(a|b)?1:0);
}
vector<ll> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R){
int n = (int)X.size();
assert(X.front()==Y.front());
if (n <= 5000){
for (int i = 0; i < n; i++)
dp[1][i+1] = X[i];
for (int i = 0; i < n; i++)
dp[i+1][1] = Y[i];
for (int i = 2; i <= n; i++)
for (int j = 2; j <= n; j++)
dp[i][j] = wow(dp[i-1][j], dp[i][j-1]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
vector<ll> ans;
for(int i = 0; i < (int)L.size(); ++i){
int x = T[i]+1, y = L[i]+1, yy = R[i]+1, xx = B[i]+1;
ans.push_back(dp[xx][yy] - dp[x-1][yy] - dp[xx][y-1] + dp[x-1][y-1]);
}
return ans;
}
bool ok = true;
for (int i = 0; i < n; i++)
ok &= X[i] == 0, ok &= Y[i] == 0;
if (ok){
vector<ll> ans;
for(int i = 0; i < (int)L.size(); ++i){
int x = T[i]+1, y = L[i]+1, yy = R[i]+1, xx = B[i]+1;
if (x == 1)
x += 1;
if (y == 1)
y += 1;
ll rec = (xx-x+1)*1LL*(yy-y+1);
if (rec % 2 == 0)
ans.push_back(rec/2);
else{
if ((xx+yy)%2)
ans.push_back(rec/2);
else
ans.push_back(rec/2+1);
}
}
return ans;
}
map<pii, int> mp;
for(int i = 1; i <= n; ++i)
mp[{1, i}] = X[i-1], mp[{i, 1}] = Y[i-1];
for(int i = 2; i <= n; ++i)
for(int j = 2; j <= 3; ++j)
mp[{i, j}] = wow(mp[{i-1, j}], mp[{i, j-1}]);
for(int i = 2; i <= 3; ++i)
for(int j = 2; j <= n; ++j)
mp[{i, j}] = wow(mp[{i-1, j}], mp[{i, j-1}]);
// int ii = 3;
// for(int jj = 3; jj <= n; ++jj)
// cnt[ii-jj+n] = mp[{ii, jj}];
for (auto [key, value]: mp)
cnt[key.first-key.second+n] = value;
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= n; j++)
arcalyk[i][j] = mp[{i,j}] + arcalyk[i][j-1];
for (int j = 1; j <= 3; j++)
for (int i = 1; i <= n; i++)
tarhun[i][j] = mp[{i,j}] + tarhun[i-1][j];
for (int i = 1; i < n+n; i++)
cnt[i] += cnt[i-1];
vector<ll> ans;
for(int i = 0; i < (int)L.size(); ++i){
int x = T[i]+1, y = L[i]+1, yy = R[i]+1, xx = B[i]+1;
ll res = 0;
while (x <= 3 and x <= xx)
res += arcalyk[x][yy]-arcalyk[x][y-1], x += 1;
if (x <= xx){
while (y <= 3 and y <= yy)
res += tarhun[xx][y]-tarhun[x-1][y], y += 1;
}
if (x <= xx and y <= yy){
int a = x-y+n, b = x-yy+n;
while (x <= xx){
res += cnt[a] - cnt[b-1];
x += 1;
a += 1;
b += 1;
}
}
ans.pb(res);
}
return ans;
}
// int main(){
// int n;
// scanf("%d", &n);
// vector<int> X, Y;
// for(int i = 1; i <= n; ++i){
// int x;
// scanf("%d", &x);
// X.pb(x);
// }
// for(int i = 1; i <= n; ++i){
// int x;
// scanf("%d", &x);
// Y.pb(x);
// }
// int q;
// scanf("%d", &q);
// vector<int> T, B, L, R;
// while(q--){
// int a, b, c, d;
// scanf("%d%d%d%d", &a, &b, &c, &d);
// T.pb(a), B.pb(b), L.pb(c), R.pb(d);
// }
// vector<ll> ans = mosaic(X, Y, T, B, L, R);
// for(ll i : ans)
// printf("%lld ", i);
// puts("");
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
4688 KB |
Output is correct |
12 |
Correct |
1 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
2 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
788 ms |
97612 KB |
Output is correct |
2 |
Correct |
774 ms |
97504 KB |
Output is correct |
3 |
Correct |
764 ms |
97724 KB |
Output is correct |
4 |
Correct |
751 ms |
97540 KB |
Output is correct |
5 |
Correct |
369 ms |
54716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
4688 KB |
Output is correct |
12 |
Correct |
1 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
2 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
190 ms |
108452 KB |
Output is correct |
19 |
Correct |
178 ms |
108484 KB |
Output is correct |
20 |
Correct |
190 ms |
108448 KB |
Output is correct |
21 |
Correct |
188 ms |
108472 KB |
Output is correct |
22 |
Correct |
184 ms |
108484 KB |
Output is correct |
23 |
Correct |
87 ms |
48828 KB |
Output is correct |
24 |
Correct |
89 ms |
49084 KB |
Output is correct |
25 |
Correct |
82 ms |
49032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
11900 KB |
Output is correct |
2 |
Correct |
96 ms |
13268 KB |
Output is correct |
3 |
Correct |
85 ms |
12884 KB |
Output is correct |
4 |
Correct |
95 ms |
12988 KB |
Output is correct |
5 |
Correct |
85 ms |
12952 KB |
Output is correct |
6 |
Correct |
88 ms |
12988 KB |
Output is correct |
7 |
Correct |
86 ms |
12996 KB |
Output is correct |
8 |
Correct |
81 ms |
12952 KB |
Output is correct |
9 |
Correct |
73 ms |
11320 KB |
Output is correct |
10 |
Correct |
85 ms |
11460 KB |
Output is correct |
11 |
Correct |
71 ms |
11452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
759 ms |
97684 KB |
Output is correct |
2 |
Correct |
770 ms |
97680 KB |
Output is correct |
3 |
Correct |
819 ms |
97724 KB |
Output is correct |
4 |
Correct |
802 ms |
97688 KB |
Output is correct |
5 |
Correct |
773 ms |
97724 KB |
Output is correct |
6 |
Correct |
386 ms |
54856 KB |
Output is correct |
7 |
Correct |
224 ms |
37432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
788 ms |
97612 KB |
Output is correct |
2 |
Correct |
774 ms |
97504 KB |
Output is correct |
3 |
Correct |
764 ms |
97724 KB |
Output is correct |
4 |
Correct |
751 ms |
97540 KB |
Output is correct |
5 |
Correct |
369 ms |
54716 KB |
Output is correct |
6 |
Correct |
759 ms |
97684 KB |
Output is correct |
7 |
Correct |
770 ms |
97680 KB |
Output is correct |
8 |
Correct |
819 ms |
97724 KB |
Output is correct |
9 |
Correct |
802 ms |
97688 KB |
Output is correct |
10 |
Correct |
773 ms |
97724 KB |
Output is correct |
11 |
Correct |
386 ms |
54856 KB |
Output is correct |
12 |
Correct |
224 ms |
37432 KB |
Output is correct |
13 |
Correct |
757 ms |
97712 KB |
Output is correct |
14 |
Correct |
810 ms |
97636 KB |
Output is correct |
15 |
Correct |
747 ms |
97640 KB |
Output is correct |
16 |
Correct |
756 ms |
97484 KB |
Output is correct |
17 |
Correct |
740 ms |
97680 KB |
Output is correct |
18 |
Correct |
773 ms |
100180 KB |
Output is correct |
19 |
Correct |
302 ms |
45704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
4688 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4432 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
2 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
788 ms |
97612 KB |
Output is correct |
20 |
Correct |
774 ms |
97504 KB |
Output is correct |
21 |
Correct |
764 ms |
97724 KB |
Output is correct |
22 |
Correct |
751 ms |
97540 KB |
Output is correct |
23 |
Correct |
369 ms |
54716 KB |
Output is correct |
24 |
Correct |
190 ms |
108452 KB |
Output is correct |
25 |
Correct |
178 ms |
108484 KB |
Output is correct |
26 |
Correct |
190 ms |
108448 KB |
Output is correct |
27 |
Correct |
188 ms |
108472 KB |
Output is correct |
28 |
Correct |
184 ms |
108484 KB |
Output is correct |
29 |
Correct |
87 ms |
48828 KB |
Output is correct |
30 |
Correct |
89 ms |
49084 KB |
Output is correct |
31 |
Correct |
82 ms |
49032 KB |
Output is correct |
32 |
Correct |
46 ms |
11900 KB |
Output is correct |
33 |
Correct |
96 ms |
13268 KB |
Output is correct |
34 |
Correct |
85 ms |
12884 KB |
Output is correct |
35 |
Correct |
95 ms |
12988 KB |
Output is correct |
36 |
Correct |
85 ms |
12952 KB |
Output is correct |
37 |
Correct |
88 ms |
12988 KB |
Output is correct |
38 |
Correct |
86 ms |
12996 KB |
Output is correct |
39 |
Correct |
81 ms |
12952 KB |
Output is correct |
40 |
Correct |
73 ms |
11320 KB |
Output is correct |
41 |
Correct |
85 ms |
11460 KB |
Output is correct |
42 |
Correct |
71 ms |
11452 KB |
Output is correct |
43 |
Correct |
759 ms |
97684 KB |
Output is correct |
44 |
Correct |
770 ms |
97680 KB |
Output is correct |
45 |
Correct |
819 ms |
97724 KB |
Output is correct |
46 |
Correct |
802 ms |
97688 KB |
Output is correct |
47 |
Correct |
773 ms |
97724 KB |
Output is correct |
48 |
Correct |
386 ms |
54856 KB |
Output is correct |
49 |
Correct |
224 ms |
37432 KB |
Output is correct |
50 |
Correct |
757 ms |
97712 KB |
Output is correct |
51 |
Correct |
810 ms |
97636 KB |
Output is correct |
52 |
Correct |
747 ms |
97640 KB |
Output is correct |
53 |
Correct |
756 ms |
97484 KB |
Output is correct |
54 |
Correct |
740 ms |
97680 KB |
Output is correct |
55 |
Correct |
773 ms |
100180 KB |
Output is correct |
56 |
Correct |
302 ms |
45704 KB |
Output is correct |
57 |
Execution timed out |
1059 ms |
97592 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |