This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define showlist(x) cerr << #x << " is "; for(auto p : x) cerr << p << " "; cerr << endl;
typedef pair<int,int> ii;
///attempt 3: push all 3x3 info up so u can store 900
/// stuff for dfs
int grid[45][45];
void dfs(int i, int j){
if(i < 0 or j < 0) return;
if(grid[i][j] == 0) return;
grid[i][j] = 0;
dfs(i+1,j);
dfs(i-1,j);
dfs(i,j+1);
dfs(i,j-1);
}
int cellToBit(int i, int j){
return (i/2) * 10 + (j/2);
}
void orTo(string &a, string b){
for(int p = 0;p < 100;p++){
if(b[p] == '1') a[p] = '1';
}
}
int n, K;
const int SQ = 10;
int group(int i, int j, int k){
int sqsize = (2 + 2*n+1 - 2*k) / 3;
int G = (i / sqsize) * 10 + j / sqsize;
return G;
}
string process(vector <vector<string>> a, int I, int J, int K, int _n){
n = _n;
//cerr << I << " " << J << " " << K << endl;
string res = string(100 ,'0');
if(K == 0){ ///first run
for(int i = 0;i <= 2;i++){
for(int j = 0;j <= 2;j++){
//show3(i,j,a[i][j]);
if(a[i][j][0] == '1'){
a[i][j] = string(100, '0');
a[i][j][((i+I)%SQ) * 10 + ((j+J)%SQ)] = '1';
//show(((i+I)%SQ) * 10 + ((j+J)%SQ));
}
else a[i][j] = string(100, '0');
}
}
}
if(K < n-1){
for(int i = 0;i <= 2;i++){
for(int j = 0;j <= 2;j++){
//show2(i,j);
//show2(group(I,J,K+1),group(i+I, j+J, K));
if(group(I,J,K+1) == group(i+I, j+J, K)){
orTo(res, a[i][j]);
}
}
}
}
else if(K == n-1){ ///last phase --> convert to binary
for(int i = 0;i < 45;i++) for(int j = 0;j < 45;j++) grid[i][j] = 0;
for(int io = 0;io <= 2;io += 1){
for(int jo = 0;jo <= 2;jo += 1){
for(int p = 0;p < 100;p++){
if(a[io][jo][p] == '1'){
int groupno = group(io,jo,K);
for(int i = 0;i <= 2*n;i++){
for(int j = 0;j <= 2*n;j++){
int P = ((i)%SQ) * 10 + ((j)%SQ);
if(groupno == group(i,j,0) and p == P){
grid[i][j] = 1;
//show2(i,j);
}
}
}
}
}
}
}
for(int i = 0;i < 2*n+1;i++){
for(int j = 0;j < 2*n+1;j++) cerr << grid[i][j];
cerr << endl;
}
///count no. of connected components via dfs
int cnt = 0;
for(int i = 0;i < 45;i++) for(int j = 0;j < 45;j++){
if(grid[i][j]){
cnt++;
dfs(i,j);
}
}
//cerr << cnt << endl;
res = string(100 ,'0');
for(int p = 0;p < 100;p++){
if(cnt % 2 == 1) res[p] = '1';
cnt /= 2;
}
}
//cerr << res << endl;
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |