# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22753 | AJAE (#40) | Young Zebra (KRIII5_YZ) | C++14 | 46 ms | 11040 KiB |
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 <cstdio>
#include <queue>
#include <vector>
using namespace std;
char str[1203][1203];
int num[1203][1203];
int grp[400*400+3];
bool chk[1203][1203];
int dr[] = {0, 0, -1, 1};
int dc[] = {1, -1, 0, 0};
int main(){
int r, c;
scanf("%d %d", &r, &c);
for(int i=0; i<r; i++)scanf("%s", str[i]);
for(int i=0; i<3*r; i++){
for(int j=0; j<3*c; j++){
str[i][j] = str[i%r][j%c];
}
}
int gtag = 0;
for(int i=r; i<2*r; i++){
for(int j=c; j<2*c; j++){
if(chk[i][j])continue;
gtag++;
queue < pair<int,int> > q;
chk[i][j] = true;
num[i][j] = gtag;
q.emplace(i, j);
while(!q.empty()){
pair<int,int> f = q.front();q.pop();
grp[gtag]++;
for(int k=0; k<4; k++){
pair<int,int> g = {f.first+dr[k], f.second+dc[k]};
if(g.first < 0 || g.second < 0 || g.first >= 3*r || g.second >= 3*c)continue;
if(chk[g.first][g.second])continue;
if(str[g.first][g.second] == str[i][j]){
q.emplace(g);
chk[g.first][g.second] = true;
num[g.first][g.second] = gtag;
}
}
}
}
}
for(int i=0; i<3*r; i++){
if(num[i][0] == num[i][3*c-1])grp[num[i][0]] = -1;
}
for(int i=0; i<3*c; i++){
if(num[0][i] == num[3*r-1][i])grp[num[0][i]] = -1;
}
// if(num[0][0] == num[3*r-1][3*c-1])grp[num[0][0]] = -1;
// if(num[0][3*c-1] == num[3*r-1][0])grp[num[0][3*c-1]] = -1;
for(int i=r; i<2*r; i++){
for(int j=c; j<2*c; j++)printf("%d ", grp[num[i][j]]);
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |