京都大学プログラミングコンテスト2015

Submission #535412

Source codeソースコード

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
char s[200][201];
int f[201];
int ans[201];
vector <int> v[201];

pair <int, int> get(int x, int y) {
    return make_pair(n - x + y, y + 1);
}

int main()
{
    while (1) {
        int x, y = 5, i, j;
        
        scanf("%d", &n);
        
        if (n == 0) break;
        
        for (i = 0; i < n; i++) {
            for (j = 0; j <= i; j++) {
                if (i == n - 1) {
                    putchar('#');
                } else {
                    pair <int, int> p = get(i, j);
                    
                    if ((p.first <= 4 && p.second == 1) || (p.first >= 4 && p.second == p.first - 1)) {
                        putchar('o');
                    } else {
                        putchar('@');
                    }
                }
            }
            
            puts("");
        }
        
        fflush(stdout);
        
        for (i = 0; i < n; i++) scanf("%s", s[i]);
        
        for (i = 0; i <= n; i++) {
            f[i] = 0;
            v[i].clear();
        }
        
        for (i = 0; i < n - 1; i++) {
            for (j = 0; j <= i; j++) {
                pair <int, int> p = get(i, j);
                
                if (s[i][j] == 'o') {
                    v[p.first].push_back(p.second);
                    v[p.second].push_back(p.first);
                }
            }
        }
        
        for (i = 1; i <= n; i++) {
            if (v[i].size() == 1 && v[v[i][0]].size() == 3) break;
        }
        
        f[i] = 1;
        ans[i] = 2;
        f[v[i][0]] = 1;
        ans[v[i][0]] = 1;
        
        for (j = 0; j < v[v[i][0]].size(); j++) {
            if (v[v[v[i][0]][j]].size() == 2) {
                f[v[v[i][0]][j]] = 1;
                ans[v[v[i][0]][j]] = 3;
            } else if (v[v[v[i][0]][j]].size() == 3) {
                f[v[v[i][0]][j]] = 1;
                ans[v[v[i][0]][j]] = 4;
                x = v[v[i][0]][j];
            }
        }
        
        while (1) {
            if (v[x].size() == 1) break;
            
            for (i = 0; i < v[x].size(); i++) {
                if (f[v[x][i]] == 1) continue;
                
                f[v[x][i]] = 1;
                ans[v[x][i]] = y++;
                x = v[x][i];
                
                break;
            }
        }
        
        for (i = 1; i <= n; i++) {
            if (i > 1) putchar(' ');
            
            printf("%d", ans[i]);
        }
        
        puts("");
        fflush(stdout);
    }
    
    return 0;
}

Submission

Task問題 I - ハウスシャッフル
User nameユーザ名 kawatea
Created time投稿日時
Language言語 C++ (GCC 4.9.2)
Status状態 AC
Score得点 300
Source lengthソースコード長 2719 Byte
File nameファイル名
Exec time実行時間 51 ms
Memory usageメモリ使用量 1436 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:22:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:46:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < n; i++) scanf("%s", s[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Small 3 / 3 01_small_00.txt,01_small_01.txt,01_small_02.txt
All 297 / 297 01_small_00.txt,01_small_01.txt,01_small_02.txt,02_medium_03.txt,02_medium_04.txt,02_medium_05.txt,02_medium_06.txt,02_medium_07.txt,03_large_08.txt,03_large_09.txt,03_large_10.txt,03_large_11.txt,03_large_12.txt,03_large_13.txt,03_large_14.txt,03_large_15.txt,03_large_16.txt,03_large_17.txt,03_large_18.txt,03_large_19.txt,03_large_20.txt,03_large_21.txt,03_large_22.txt,03_large_23.txt,03_large_24.txt,03_large_25.txt,03_large_26.txt,03_large_27.txt,03_large_28.txt,03_large_29.txt,03_large_30.txt,03_large_31.txt,03_large_32.txt,03_large_33.txt,03_large_34.txt,03_large_35.txt,03_large_36.txt,03_large_37.txt,03_large_38.txt,03_large_39.txt,03_large_40.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01_small_00.txt AC 39 ms 1164 KB
01_small_01.txt AC 39 ms 1164 KB
01_small_02.txt AC 33 ms 1156 KB
02_medium_03.txt AC 32 ms 1152 KB
02_medium_04.txt AC 33 ms 1068 KB
02_medium_05.txt AC 31 ms 1148 KB
02_medium_06.txt AC 35 ms 1156 KB
02_medium_07.txt AC 33 ms 1264 KB
03_large_08.txt AC 34 ms 1240 KB
03_large_09.txt AC 39 ms 1396 KB
03_large_10.txt AC 38 ms 1356 KB
03_large_11.txt AC 45 ms 1256 KB
03_large_12.txt AC 42 ms 1216 KB
03_large_13.txt AC 45 ms 1324 KB
03_large_14.txt AC 43 ms 1280 KB
03_large_15.txt AC 40 ms 1404 KB
03_large_16.txt AC 43 ms 1324 KB
03_large_17.txt AC 41 ms 1308 KB
03_large_18.txt AC 39 ms 1316 KB
03_large_19.txt AC 40 ms 1388 KB
03_large_20.txt AC 41 ms 1184 KB
03_large_21.txt AC 39 ms 1284 KB
03_large_22.txt AC 43 ms 1428 KB
03_large_23.txt AC 43 ms 1308 KB
03_large_24.txt AC 42 ms 1296 KB
03_large_25.txt AC 47 ms 1252 KB
03_large_26.txt AC 48 ms 1436 KB
03_large_27.txt AC 47 ms 1192 KB
03_large_28.txt AC 48 ms 1408 KB
03_large_29.txt AC 49 ms 1312 KB
03_large_30.txt AC 48 ms 1320 KB
03_large_31.txt AC 49 ms 1368 KB
03_large_32.txt AC 47 ms 1436 KB
03_large_33.txt AC 47 ms 1428 KB
03_large_34.txt AC 46 ms 1432 KB
03_large_35.txt AC 47 ms 1308 KB
03_large_36.txt AC 51 ms 1332 KB
03_large_37.txt AC 46 ms 1424 KB
03_large_38.txt AC 48 ms 1416 KB
03_large_39.txt AC 48 ms 1356 KB
03_large_40.txt AC 48 ms 1376 KB