# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133555 | 2019-07-21T04:47:22 Z | tlwpdus | Friends (BOI17_friends) | C++11 | 773 ms | 20992 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; int n, p, q; vector<int> lis[3000]; int mat[3000][3000]; void pung() { puts("detention"); exit(0); } int gn; int grp[3000][3000], gs[3000]; int chk[3000], inc[3000]; int sel[3000], cand[3000]; int sb, cb; bool bt(int nq, int dep) { if (sb<=p&&nq<=q) return true; if (dep>=p+q||!cb||cb+sb>p+q) return false; int v = cand[--cb]; inc[v] = 0; chk[v] = 0; if (bt(nq,dep+1)) { chk[v] = -1; inc[v] = 0; return true; } sel[sb++] = v; chk[v] = 1; int psz = cb; for (int &there : lis[v]) { if (chk[there]==-1&&!inc[there]) { cand[cb++] = there; inc[there] = 1; } nq -= (int)(chk[there]==1)*2-1; } if (bt(nq,dep+1)) { grp[gn][gs[gn]++] = v; chk[v] = -1; return true; } sb--; chk[v] = -1; while(cb>psz) inc[cand[--cb]] = 0; cand[cb++] = v; inc[v] = 1; return false; } void solve(int a, int b) { for (int i=0;i<gs[a];i++) chk[grp[a][i]]++; for (int i=0;i<gs[b];i++) chk[grp[b][i]]+=2; int c[2] = {0,0}; for (int i=0;i<gs[a];i++) { int v = grp[a][i]; if (chk[v]!=3) continue; for (int &w : lis[v]) { if (chk[w]==3||chk[w]==0) continue; c[chk[w]-1]++; } } int t = (c[0]<c[1]?a:b); for (int i=0;i<gs[t];i++) { if (chk[grp[t][i]]!=3) continue; swap(grp[t][i],grp[t][--gs[t]]); i--; } for (int i=0;i<gs[a];i++) chk[grp[a][i]]=0; for (int i=0;i<gs[b];i++) chk[grp[b][i]]=0; } set<pii> se; int main() { scanf("%d%d%d",&n,&p,&q); for (int i=0;i<n;i++) { int mi; scanf("%d",&mi); if (mi>=p+q) pung(); for (int j=0;j<mi;j++) { int a; scanf("%d",&a); mat[i][a] = 1; lis[i].push_back(a); if (a<=i) { if (se.find({a,i})==se.end()) pung(); se.erase({a,i}); } else se.insert({i,a}); } } if (!se.empty()) pung(); memset(chk,-1,sizeof(chk)); for (int i=0;i<n;i++) { chk[i] = 1; for (int j=0;j<n;j++) inc[j] = 0; sb = cb = 0; sel[sb++] = i; for (int &there : lis[i]) { cand[cb++] = there; inc[there] = 1; } if (!bt(lis[i].size(),0)) pung(); else { grp[gn][gs[gn]++] = i; chk[i] = -1; } gn++; } memset(chk,0,sizeof(chk)); for (int i=0;i<n;i++) { for (int j=i+1;j<n;j++) { solve(i,j); } } puts("home"); int cnt = 0; for (int i=0;i<n;i++) cnt += (gs[i]>0); printf("%d\n",cnt); for (int i=0;i<n;i++) { if (!gs[i]) continue; printf("%d ",gs[i]); for (int j=0;j<gs[i];j++) printf("%d ",grp[i][j]); printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 476 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 2 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 7 ms | 2040 KB | Output is correct |
3 | Correct | 4 ms | 1656 KB | Output is correct |
4 | Correct | 4 ms | 1656 KB | Output is correct |
5 | Correct | 4 ms | 2140 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 18 ms | 2424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 7 ms | 2040 KB | Output is correct |
3 | Correct | 4 ms | 1656 KB | Output is correct |
4 | Correct | 4 ms | 1656 KB | Output is correct |
5 | Correct | 4 ms | 2140 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 18 ms | 2424 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 89 ms | 8656 KB | Output is correct |
11 | Correct | 71 ms | 10616 KB | Output is correct |
12 | Correct | 94 ms | 10232 KB | Output is correct |
13 | Correct | 99 ms | 10604 KB | Output is correct |
14 | Correct | 10 ms | 7900 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 476 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 2 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 380 KB | Output is correct |
10 | Correct | 7 ms | 2040 KB | Output is correct |
11 | Correct | 4 ms | 1656 KB | Output is correct |
12 | Correct | 4 ms | 1656 KB | Output is correct |
13 | Correct | 4 ms | 2140 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 1272 KB | Output is correct |
16 | Correct | 18 ms | 2424 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 89 ms | 8656 KB | Output is correct |
19 | Correct | 71 ms | 10616 KB | Output is correct |
20 | Correct | 94 ms | 10232 KB | Output is correct |
21 | Correct | 99 ms | 10604 KB | Output is correct |
22 | Correct | 10 ms | 7900 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 2 ms | 504 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 96 ms | 15972 KB | Output is correct |
27 | Correct | 74 ms | 15172 KB | Output is correct |
28 | Correct | 91 ms | 13936 KB | Output is correct |
29 | Correct | 74 ms | 5868 KB | Output is correct |
30 | Correct | 27 ms | 7972 KB | Output is correct |
31 | Correct | 10 ms | 5948 KB | Output is correct |
32 | Correct | 2 ms | 504 KB | Output is correct |
33 | Correct | 773 ms | 20992 KB | Output is correct |
34 | Correct | 104 ms | 12528 KB | Output is correct |