답안 #88734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88734 2018-12-08T09:09:04 Z popovicirobert 컴퓨터 네트워크 (BOI14_network) C++14
100 / 100
122 ms 59024 KB
#include <bits/stdc++.h>

#include "network.h"

/*static const int MAX_N = 1010;

static int N, a, b, M,
           pingCount,
           routeLength, current;
static int distance[MAX_N][MAX_N];

static void raiseError (const char* message)
{
    printf ("ERROR\n%s\n", message);
    exit (0);
}

int ping (int i, int j)
{
    if (i < 1 || j < 1 || i > N || j > N || i == j)
        raiseError ("ping called with invalid arguments");

    ++pingCount;
    if (pingCount > M)
        raiseError ("Too many calls to ping");

    return distance[i-1][j-1];
}


void travelTo (int k)
{
    if (k < 1 || k > N)
        raiseError ("travelTo called with invalid argument");

    if (k == current || distance[current-1][k-1] > 0)
        raiseError ("Travelling to nonadjacent computer");

    ++routeLength;
    if (routeLength > distance[a-1][b-1] + 1)
        raiseError ("Route is too long");

    current = k;
}*/

const int MAXN = 1000;

int distB[MAXN + 1];
bool distA[MAXN + 1];

void findRoute(int N, int a, int b) {
    int i;
    for(i = 1; i <= N; i++) {
        if(i != b)
            distB[i] = ping(b, i) + 1;
    }
    distA[a] = 1;
    int d = distB[a];
    while(d > 0) {
        d--;
        for(i = 1; i <= N; i++) {
            if(distA[i] == 0 && distB[i] + 1 == distB[a]) {
                if(ping(a, i) + 1 == 1) {
                    a = i;
                    travelTo(a);
                    break;
                }
                distA[i] = 1;
            }
        }
    }
}

/*int main()
{
    scanf ("%d%d%d%d", &N, &a, &b, &M);
    for (int u = 0; u < N; ++u)
        for (int v = 0; v < N; ++v)
            scanf("%d", &distance[u][v]);

    pingCount = 0;
    routeLength = 0;
    current = a;

    findRoute (N, a, b);

    if (current != b)
        raiseError ("Message has not reached its target");

    if (routeLength < distance[a-1][b-1] + 1)
        raiseError ("Unexpected: route is too short");

    printf ("OK\n");

    return 0;
}*/


Compilation message

grader.c: In function 'int main()':
grader.c:48:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d%d%d%d", &N, &a, &b, &M);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
grader.c:51:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &distance[u][v]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 8184 KB Output is correct
2 Correct 116 ms 11420 KB Output is correct
3 Correct 103 ms 14276 KB Output is correct
4 Correct 103 ms 17300 KB Output is correct
5 Correct 102 ms 19736 KB Output is correct
6 Correct 103 ms 22148 KB Output is correct
7 Correct 2 ms 22148 KB Output is correct
8 Correct 3 ms 22148 KB Output is correct
9 Correct 2 ms 22148 KB Output is correct
10 Correct 2 ms 22148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 24776 KB Output is correct
2 Correct 28 ms 24776 KB Output is correct
3 Correct 120 ms 28896 KB Output is correct
4 Correct 91 ms 30880 KB Output is correct
5 Correct 119 ms 34624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 36944 KB Output is correct
2 Correct 27 ms 36944 KB Output is correct
3 Correct 119 ms 41084 KB Output is correct
4 Correct 95 ms 43104 KB Output is correct
5 Correct 119 ms 46728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 49376 KB Output is correct
2 Correct 28 ms 49376 KB Output is correct
3 Correct 122 ms 53516 KB Output is correct
4 Correct 93 ms 55428 KB Output is correct
5 Correct 120 ms 59024 KB Output is correct