답안 #22615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22615 2017-04-30T05:58:13 Z - - - - - - - List of honorable mention follows - - - - - - -(#999, xhae, ainu7, littlesheep) Young Zebra (KRIII5_YZ) C++11
2 / 7
73 ms 16460 KB
#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

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]);
                                    ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 49 ms 10328 KB Output is partially correct
2 Correct 36 ms 11732 KB Output is correct
3 Correct 49 ms 11704 KB Output is correct
4 Correct 53 ms 7264 KB Output is correct
5 Correct 43 ms 6000 KB Output is correct
6 Correct 43 ms 5716 KB Output is correct
7 Partially correct 43 ms 11924 KB Output is partially correct
8 Correct 39 ms 10836 KB Output is correct
9 Correct 46 ms 11928 KB Output is correct
10 Partially correct 43 ms 10840 KB Output is partially correct
11 Correct 43 ms 12424 KB Output is correct
12 Correct 46 ms 16460 KB Output is correct
13 Partially correct 56 ms 10368 KB Output is partially correct
14 Partially correct 39 ms 9064 KB Output is partially correct
15 Correct 43 ms 7612 KB Output is correct
16 Partially correct 46 ms 9060 KB Output is partially correct
17 Correct 33 ms 10816 KB Output is correct
18 Correct 39 ms 10812 KB Output is correct
19 Correct 73 ms 4768 KB Output is correct
20 Correct 56 ms 8392 KB Output is correct
21 Partially correct 53 ms 12876 KB Output is partially correct
22 Partially correct 39 ms 12688 KB Output is partially correct
23 Correct 56 ms 8860 KB Output is correct
24 Correct 46 ms 7340 KB Output is correct
25 Correct 43 ms 9200 KB Output is correct
26 Correct 0 ms 4768 KB Output is correct
27 Correct 0 ms 4768 KB Output is correct
28 Correct 0 ms 4864 KB Output is correct
29 Correct 0 ms 4860 KB Output is correct
30 Correct 0 ms 4768 KB Output is correct
31 Correct 0 ms 4768 KB Output is correct
32 Correct 0 ms 4768 KB Output is correct
33 Correct 0 ms 4768 KB Output is correct
34 Correct 0 ms 4768 KB Output is correct
35 Correct 0 ms 4768 KB Output is correct
36 Correct 3 ms 5288 KB Output is correct
37 Correct 0 ms 4972 KB Output is correct
38 Correct 3 ms 4768 KB Output is correct
39 Correct 3 ms 4972 KB Output is correct
40 Correct 3 ms 5268 KB Output is correct