# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
645698 |
2022-09-27T16:48:56 Z |
Tenis0206 |
Mars (APIO22_mars) |
C++17 |
|
8 ms |
2476 KB |
#include <bits/stdc++.h>
using namespace std;
int n;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int X[105],Y[105],newx[105],newy[105],oldx[105],oldy[105];
int d[105][105];
void preset()
{
int cnt = 0;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
++cnt;
X[cnt] = i * ((2 * n + 1) / 3);
Y[cnt] = j * ((2 * n + 1) / 3);
}
}
}
void calc_poz(int nr)
{
oldx[1] = oldy[1] = newx[1] = oldx[1] = 1;
newy[2] = max(2,Y[2] - 2 * nr), oldy[2] = max(2,Y[2] - 2 * (nr - 1)), newx[2] = X[2], oldx[2] = X[2];
newy[3] = max(3,Y[3] - 2 * nr), oldy[3] = max(3,Y[3] - 2 * (nr - 1)), newx[3] = X[3], oldx[3] = X[3];
newx[4] = max(2,X[4] - 2 * nr), oldx[4] = max(2,X[4] - 2 * (nr - 1)), newy[4] = Y[4], oldy[4] = Y[4];
newx[5] = max(2,X[5] - 2 * nr), oldx[5] = max(2,X[5] - 2 * (nr - 1)), newy[5] = max(2,Y[5] - 2 * nr), oldy[5] = max(2,Y[5] - 2 * (nr - 1));
newx[6] = max(2,X[6] - 2 * nr), oldx[6] = max(2,X[6] - 2 * (nr - 1)), newy[6] = max(3,Y[6] - 2 * nr), oldy[6] = max(3,Y[6] - 2 * (nr - 1));
newx[7] = max(3,X[7] - 2 * nr), oldx[7] = max(3,X[7] - 2 * (nr - 1)), newy[7] = Y[7], oldy[7] = Y[7];
newx[8] = max(3,X[8] - 2 * nr), oldx[8] = max(3,X[8] - 2 * (nr - 1)), newy[8] = max(2,Y[8] - 2 * nr), oldy[8] = max(2,Y[8] - 2 * (nr - 1));
newx[9] = max(3,X[9] - 2 * nr), oldx[9] = max(3,X[9] - 2 * (nr - 1)), newy[9] = max(3,Y[9] - 2 * nr), oldy[9] = max(3,Y[9] - 2 * (nr - 1));
}
pair<int,int> get_poz_in_square(int p, int c)
{
int x = 0, y = 0;
if(c!=3 && c!=6 && c!=9)
{
x = p / ((2 * n + 1) / 3);
y = p % ((2 * n + 1) / 3);
}
else
{
x = p / (2 * n + 1 - 2 * ((2 * n + 1) / 3));
y = p % (2 * n + 1 - 2 * ((2 * n + 1) / 3));
}
return {x,y};
}
int get_poz_in_string(int x, int y, int c)
{
int p = 0;
if(c!=3 && c!=6 && c!=9)
{
p = x * ((2 * n + 1) / 3) + y;
}
else
{
p = x * (2 * n + 1 - 2 * ((2 * n + 1) / 3)) + y;
}
return p;
}
int get_square(int x, int y)
{
int cnt = 0;
int rez = 0;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
++cnt;
if(X[cnt]<=x && Y[cnt]<=y)
{
rez = cnt;
}
}
}
return rez;
}
void Fill(int i, int j)
{
d[i][j] = 0;
for(int p=0; p<4; p++)
{
int xx = i + dx[p];
int yy = j + dy[p];
if(xx >= 0 && xx <= 2 * n && yy >= 0 && yy <= 2 * n && d[xx][yy]!=0)
{
Fill(xx,yy);
}
}
}
string process(vector<vector<string>> a, int x, int y, int k, int N)
{
n = N;
preset();
if(k==n-1)
{
if(k!=0)
{
int cnt = 0;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
++cnt;
for(int p=0; p<100; p++)
{
int xx = X[cnt] + get_poz_in_square(p,cnt).first;
int yy = Y[cnt] + get_poz_in_square(p,cnt).second;
d[xx][yy] = a[i][j][p] - '0';
}
}
}
}
else
{
for(int i=0; i<2*n+1; i++)
{
for(int j=0; j<2*n+1; j++)
{
d[i][j] = a[i][j][0] - '0';
}
}
}
int nr = 0;
for(int i=0; i<2*n+1; i++)
{
for(int j=0; j<2*n+1; j++)
{
if(d[i][j])
{
++nr;
Fill(i,j);
}
}
}
string rez;
for(int b=0; b<100; b++)
{
if(b < 30)
{
rez.push_back('0' + ((nr & (1<<b))!=0));
}
else
{
rez.push_back('0');
}
}
return rez;
}
int m = 2 * (n - k - 1);
int c = get_square(x,y);
if(X[9] <= m)
{
if(x!=m && y!=m)
{
return a[0][0];
}
string rez;
rez.resize(100);
for(int p=0; p<100; p++)
{
rez[p] = '0';
}
if(k==0)
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
int xx = x + i;
int yy = y + j;
if(get_square(xx,yy)==c)
{
int p = get_poz_in_string(xx-X[c],yy-Y[c],c);
rez[p] = a[i][j][0];
}
}
}
}
else
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
int xx = x + i;
int yy = y + j;
if(get_square(xx,yy)==c)
{
for(int p=0; p<100; p++)
{
if(a[i][j][p]=='1')
{
rez[p] = '1';
}
}
}
}
}
}
return rez;
}
else
{
int nr = (X[9] - m) / 2;
calc_poz(nr);
for(int i=1; i<=9; i++)
{
if(x==newx[i] && y==newy[i])
{
return a[oldx[i] - x][oldy[i] - y];
}
}
return a[0][0];
}
}
Compilation message
mars.cpp: In function 'void calc_poz(int)':
mars.cpp:30:13: warning: operation on 'oldx[1]' may be undefined [-Wsequence-point]
30 | oldx[1] = oldy[1] = newx[1] = oldx[1] = 1;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2228 KB |
Output is correct |
2 |
Correct |
8 ms |
2392 KB |
Output is correct |
3 |
Correct |
8 ms |
2332 KB |
Output is correct |
4 |
Correct |
8 ms |
2268 KB |
Output is correct |
5 |
Correct |
8 ms |
2364 KB |
Output is correct |
6 |
Correct |
8 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |