Submission #957486

# Submission time Handle Problem Language Result Execution time Memory
957486 2024-04-03T21:15:10 Z YassirSalama Computer Network (BOI14_network) C++17
0 / 100
79 ms 4408 KB
#include "network.h"
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
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__);
#else
#define dbg(...) 1337;
#endif
#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()
vector<int> path;
int n;
int c;
void solve(int l,int r,int m,int i){
    dbg(l,r,m,i)
    if(l==r){
        return;
    }
    for(int i=1;i<=n;i++){
        if(i==l||i==r) continue;
        int x=ping(l,i);
        int y=ping(i,r);
        dbg(x,y,c,m)
        if(x+y+1==m){
            path[m]=i;
            solve(l,i,m/2,m/2);
            solve(i,r,m/2,m+m/2);
        }
    }
}
void findRoute (int N, int a, int b)
{
    /*
     *  Obviously, this is not a good solution.
     *  Replace it with your own code.
     */
    n=N;
    c=ping(a,b);
    path.resize(c+1,0);
    solve(a,b,(c+1)/2,c/2);
    for(auto x:path){
        dbg(x)
        if(x==0) continue;
        travelTo(x);
    }
    travelTo(b);
    
}


#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 di[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 di[i-1][j-1];
}

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

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

    ++routeLength;
    if (routeLength > di[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", &di[u][v]);

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

    findRoute (N, a, b);

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

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

    printf ("OK\n");

    return 0;
}
#endif

Compilation message

network.cpp: In function 'void solve(int, int, int, int)':
network.cpp:11:18: warning: statement has no effect [-Wunused-value]
   11 | #define dbg(...) 1337;
      |                  ^~~~
network.cpp:24:5: note: in expansion of macro 'dbg'
   24 |     dbg(l,r,m,i)
      |     ^~~
network.cpp:11:18: warning: statement has no effect [-Wunused-value]
   11 | #define dbg(...) 1337;
      |                  ^~~~
network.cpp:32:9: note: in expansion of macro 'dbg'
   32 |         dbg(x,y,c,m)
      |         ^~~
network.cpp: In function 'void findRoute(int, int, int)':
network.cpp:11:18: warning: statement has no effect [-Wunused-value]
   11 | #define dbg(...) 1337;
      |                  ^~~~
network.cpp:51:9: note: in expansion of macro 'dbg'
   51 |         dbg(x)
      |         ^~~
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]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 4176 KB Travelling to nonadjacent computer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 4408 KB Travelling to nonadjacent computer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 4300 KB Travelling to nonadjacent computer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 4148 KB Travelling to nonadjacent computer
2 Halted 0 ms 0 KB -