답안 #866725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866725 2023-10-26T21:41:48 Z YassirSalama 컴퓨터 네트워크 (BOI14_network) C++17
25 / 100
68 ms 10320 KB
#include "network.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <functional>
#include <iterator>
using namespace std;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
const int MAXN=1500;
vector<int> v[MAXN];
bool visited[MAXN][MAXN];
int par[MAXN];
bool vis[MAXN];

void findRoute (int n, int a, int b)
{
    memset(visited,false,sizeof(visited));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(!(i^j)) continue;
            if(visited[i][j]) continue;
            if(ping(i,j)==0){
                visited[i][j]=true;
                visited[j][i]=true;
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }
    memset(par,-1,sizeof(par));
    queue<int> q;
    q.push({a});
    bool inqueue[MAXN];
    memset(inqueue,false,sizeof(inqueue));
    while(!q.empty()){
        int node=q.front();
        q.pop();
        if(vis[node]) continue;
        vis[node]=true;
        if(node==b){
            vector<int> vv;
            while(node!=-1){
                vv.push_back(node);
                node=par[node];
            }
            vv.pop_back();
            reverse(all(vv));
            for(auto x:vv) travelTo(x);
            return;
        }
        for(auto x:v[node]){
            if(vis[x]||inqueue[x]) continue;
            par[x]=node;
            inqueue[x]=true;
            q.push(x);
        }
    }

}


#ifdef IOI
#include <cstdio>
#include <cstdlib>

#include "network.h"

static const int MAX_N = 1010;

static int N, a, b, M,
           pingCount,
           routeLength, current;
static int dist[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 dist[i-1][j-1];
}

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

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

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

    current = k;
}

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", &dist[u][v]);

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

    findRoute (N, a, b);

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

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

    printf ("OK\n");

    return 0;
}

#endif

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]
   48 |     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]
   51 |             scanf("%d", &distance[u][v]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 10264 KB Too many calls to ping
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 9044 KB Output is correct
2 Correct 16 ms 5212 KB Output is correct
3 Correct 67 ms 10152 KB Output is correct
4 Correct 64 ms 8528 KB Output is correct
5 Correct 68 ms 10320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 8996 KB Too many calls to ping
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 9012 KB Too many calls to ping
2 Halted 0 ms 0 KB -