# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22940 | dotorya | Young Zebra (KRIII5_YZ) | C++14 | 43 ms | 7256 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 <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 1034567890123456789ll;
const db PI = acos(-1);
const db ERR = 1E-11;
char in[405][405];
pii dchk[405][405];
int ans[405][405];
int main() {
int N, M, i, j, k, l;
scanf("%d %d", &N, &M);
for (i = 0; i < N; i++) scanf("%s", in[i]);
for (i = 0; i < N; i++) for (j = 0; j < M; j++) dchk[i][j] = pii(INF, INF);
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
if (dchk[i][j].first != INF) continue;
vector <pii> Vu;
dchk[i][j] = pii(0, 0);
Vu.emplace_back(i, j);
bool tchk = false;
for (k = 0; k < Vu.size(); k++) {
for (l = 0; l < 4; l++) {
int x = (Vu[k].first + "1102"[l] - '1' + N) % N;
int y = (Vu[k].second + "0211"[l] - '1' + M) % M;
if (in[x][y] != in[Vu[k].first][Vu[k].second]) continue;
pii v = dchk[Vu[k].first][Vu[k].second];
if (Vu[k].second == 0 && l == 0) v.second--;
if (Vu[k].second == M - 1 && l == 1) v.second++;
if (Vu[k].first == 0 && l == 2) v.first--;
if (Vu[k].first == N - 1 && l == 3) v.first++;
if (dchk[x][y].first != INF && dchk[x][y] != v) tchk = true;
else if (dchk[x][y].first == INF) {
dchk[x][y] = v;
Vu.emplace_back(x, y);
}
}
}
if (tchk) for (auto it : Vu) ans[it.first][it.second] = -1;
else for(auto it : Vu) ans[it.first][it.second] = (int)Vu.size();
Vu.clear();
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) printf("%d ", ans[i][j]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |