답안 #13123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13123 2015-01-31T10:55:42 Z gs14004 탐사 (KOI13_probe) C++14
19 / 19
7 ms 428 KB
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int adj[50][50], k, n;
int hard[50];

int main(){
    memset(adj,0x3f,sizeof(adj));
    memset(hard,-1,sizeof(hard));
    scanf("%d %d",&k,&n);
    for (int i=1; i<=k; i++) {
        adj[i][i+1] = 1;
        adj[i+1][i] = 0;
        adj[i][i] = 0;
    }
    for (int i=0; i<n; i++) {
        int x,y,z;
        scanf("%d %d %d",&x,&y,&z);
        if(x != y && adj[x][y+1] < 1e9 && adj[x][y+1] != z){
            puts("NONE");
            return 0;
        }
        if(x == y){
            if(hard[x] != -1 && hard[x] != z){
                puts("NONE");
                return 0;
            }
            hard[x] = z;
        }
        adj[x][y+1] = z;
        adj[y+1][x] = -z;
    }
    for (int i=1; i<=k+1; i++) {
        for (int j=1; j<=k+1; j++) {
            for (int l=1; l<=k+1; l++) {
                adj[j][l] = min(adj[j][l],adj[j][i] + adj[i][l]);
            }
        }
    }
    for (int i=1; i<=k+1; i++) {
        if(adj[i][i] < 0){
            puts("NONE");
            return 0;
        }
    }
    for (int i=1; i<=k; i++) {
        if(adj[i][i+1] > 1 || adj[i][i+1] < 0 || (~hard[i] && adj[i][i+1] != hard[i])){
            puts("NONE");
            return 0;
        }
    }
    for (int i=1; i<=k; i++) {
        if(adj[1][i+1] - adj[1][i]) putchar('#');
        else putchar('-');
    }
}

Compilation message

probe.cpp: In function 'int main()':
probe.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&k,&n);
     ~~~~~^~~~~~~~~~~~~~~
probe.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&x,&y,&z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 404 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 296 KB Output is correct