Submission #22615

#TimeUsernameProblemLanguageResultExecution timeMemory
22615- - - - - - - List of honorable mention follows - - - - - - - (#40)Young Zebra (KRIII5_YZ)C++11
2 / 7
73 ms16460 KiB
#include <functional> #include <algorithm> #include <stdexcept> #include <iostream> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <cstdlib> #include <cstring> #include <utility> #include <cctype> #include <vector> #include <string> #include <bitset> #include <cmath> #include <queue> #include <stdint.h> #include <stdio.h> #include <stack> #include <ctime> #include <list> #include <map> #include <set> #include <tuple> #include <unordered_set> #include <assert.h> #define REP(i,n) for(int i=0;i<n;i++) #define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++) #define ALL(x) x.begin(),x.end() #define SORT(x) sort(ALL(x)) #define CLEAR(x) memset(x,0,sizeof(x)) #define FILL(x,c) memset(x,c,sizeof(x)) using namespace std; #define PB push_back #define MP make_pair typedef map<int,int> MII; typedef map<string,int> MSI; typedef vector<int> VI; typedef vector<string> VS; typedef vector<long double> VD; typedef pair<int,int> PII; typedef long long int64; typedef long long LL; typedef unsigned int UI; typedef long double LD; typedef unsigned long long ULL; const int N = 407; char table[N][N]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; int n, m; void dfs(int x, int y, int result[N][N], bool allowTB, bool allowLR, int col) { result[x][y] = col; REP(d, 4) { int nx = x + dx[d]; int ny = y + dy[d]; if ((nx < 0 || nx >= n) && !allowTB) { continue; } nx = (nx + n) % n; if ((ny < 0 || ny >= m) && !allowLR) { continue; } ny = (ny + m) % m; if (table[nx][ny] != table[x][y]) { continue; } if (result[nx][ny] != -1) { assert(result[nx][ny] == col); continue; } dfs(nx, ny, result, allowTB, allowLR, col); } } void doDfs(int result[N][N], bool allowTB, bool allowLR) { REP(i, n) REP(j, m) result[i][j] = -1; int colors = 0; REP(i, n) REP(j, m) if (result[i][j] == -1) { dfs(i, j, result, allowTB, allowLR, colors++); } } int conn0[N][N]; int conn1[N][N]; int conn2[N][N]; int colorCount[N * N]; int main() { cin >> n >> m; REP(i, n) scanf("%s", table[i]); doDfs(conn0, true, true); doDfs(conn1, true, false); doDfs(conn2, false, true); REP(i, n) REP(j, m) ++colorCount[conn0[i][j]]; REP(j, m) if (table[0][j] == table[n - 1][j]) { if (conn2[0][j] == conn2[n - 1][j]) { colorCount[conn0[0][j]] = -1; } } REP(i, n) if (table[i][0] == table[i][m - 1]) { if (conn1[i][0] == conn1[i][m - 1]) { colorCount[conn0[i][0]] = -1; } } REP(i, n) { REP(j, m) { if (j) printf(" "); printf("%d", colorCount[conn0[i][j]]); } printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:100:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     REP(i, n) scanf("%s", table[i]);
                                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...