#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()
void findRoute (int N, int a, int b)
{
/*
* Obviously, this is not a good solution.
* Replace it with your own code.
*/
int n=N;
vector<int> d[N+1],d2[n+1];
int f=ping(a,b);
for(int i=1;i<=n;i++){
if(i==a||i==b) continue;
int x=ping(a,i),y=ping(i,b);
if(x+y+1==f){
d[x].pb(i);
d2[y].pb(i);
}
}
for(int i=0;i<=n;i++){
// dbg(i)
for(auto x:d[i]){
// dbg(x)
travelTo(x);
break;
// dbg(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
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 |
Correct |
61 ms |
8020 KB |
Output is correct |
2 |
Correct |
63 ms |
7508 KB |
Output is correct |
3 |
Correct |
57 ms |
6992 KB |
Output is correct |
4 |
Correct |
61 ms |
7056 KB |
Output is correct |
5 |
Correct |
59 ms |
6856 KB |
Output is correct |
6 |
Correct |
59 ms |
6800 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
73 ms |
6732 KB |
Travelling to nonadjacent computer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
6740 KB |
Travelling to nonadjacent computer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
6740 KB |
Travelling to nonadjacent computer |
2 |
Halted |
0 ms |
0 KB |
- |