#include <bits/stdc++.h>
using namespace std;
const int MAXN=203;
vector<int> g[MAXN];
int dp[MAXN][MAXN][MAXN];
int n, k;
int dist(int a, int b) { if(b>a) return b-a; else return n-a+b; }
bool dentro(int ini, int fim, int val) {
if(ini<=fim) return (ini<=val&&val<=fim);
else {
if(val==ini||val==fim) return 1;
fim+=n; val+=n;
return (ini<=val&&val<=fim);
}
}
//int parte(int ini, int mid, int fim, int val) { if(ini<=fim) return (mid<=val&&val<=fim); else return (mid>=va) }
int fazdp(int cur, int ini, int fim) {
if(dp[cur][ini][fim]!=-1) return dp[cur][ini][fim];
if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
//printf("chama %d %d %d\n", cur, ini, fim);
dp[cur][ini][fim]=0; int resp=0;
for(auto viz : g[cur]) {
//if(!dentro(ini, fim, viz)) printf("fora %d %d %d\n", ini, fim, viz);
if(!dentro(ini, fim, viz)) continue;
int vini, vfim;
if(viz>cur) {
vini=viz+1;
vfim=fim;
}
else {
vini=ini;
vfim=viz-1;
}
if(vini>n) vini%=n; if(vfim>n) vfim%=n;
//printf("viz: %d %d %d // %d %d\n", ini, fim, viz, vini, vfim);
resp=max(resp, fazdp(viz, vini, vfim)+1 );
}
//printf("%d %d %d = %d\n", cur, ini, fim, resp);
return dp[cur][ini][fim]=resp;
}
int main() {
scanf("%d %d", &n, &k);
for(int i=1; i<=n; i++) {
while(1) {
int a; scanf("%d", &a);
if(a==0) break;
g[i].push_back(a);
}
}
memset(dp, -1, sizeof(dp)); int resp=0; int respp=1;
for(int i=1; i<=n; i++) {
if(fazdp(i, i+1, i-1)>resp) {
resp=fazdp(i, i+1, i-1);
respp=i;
}
}
printf("%d\n%d\n", resp, respp);
}
Compilation message
race.cpp: In function 'int fazdp(int, int, int)':
race.cpp:22:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
^~
race.cpp:22:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
^~
race.cpp:40:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(vini>n) vini%=n; if(vfim>n) vfim%=n;
^~
race.cpp:40:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(vini>n) vini%=n; if(vfim>n) vfim%=n;
^~
race.cpp: In function 'int main()':
race.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
race.cpp:55:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int a; scanf("%d", &a);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
28 ms |
33016 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Runtime error |
26 ms |
33132 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
3 |
Runtime error |
28 ms |
33208 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
4 |
Runtime error |
27 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
5 |
Runtime error |
27 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
6 |
Runtime error |
29 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
7 |
Runtime error |
31 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
8 |
Runtime error |
31 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
9 |
Runtime error |
35 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
10 |
Runtime error |
44 ms |
33416 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
11 |
Runtime error |
30 ms |
33432 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
12 |
Runtime error |
46 ms |
33452 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
13 |
Runtime error |
5 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
4 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
5 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
6 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
6 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
5 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
8 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
9 ms |
33452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |