# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
133540 | 2019-07-21T04:18:47 Z | tlwpdus | Friends (BOI17_friends) | C++11 | 1000 ms | 11140 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; vector<int> grp[3000]; int chk[3000], inc[3000]; vector<int> sel, cand, nop; void print() { printf("sel : "); for (int &v : sel) printf("%d ",v); printf("\n"); printf("nop : "); for (int &v : nop) printf("%d ",v); printf("\n"); printf("cand : "); for (int &v : cand) printf("%d ",v); printf("\n\n"); } bool bt(int nq, int dep) { /* printf("%d, %d\n",sel.size(),nq); print(); */ if (sel.size()<=p&&nq<=q) return true; if (dep>=p+q||cand.empty()) return false; int v = cand.back(); cand.pop_back(); inc[v] = 0; chk[v] = 0; nop.push_back(v); if (bt(nq,dep+1)) { chk[v] = -1; inc[v] = 0; return true; } //for (int i=0;i<n;i++) printf("%2d ",chk[i]); printf("\n"); //for (int i=0;i<n;i++) printf("%2d ",inc[i]); printf("\n"); nop.pop_back(); sel.push_back(v); chk[v] = 1; int psz = cand.size(); for (int &there : lis[v]) { if (chk[there]==-1&&!inc[there]) { cand.push_back(there); inc[there] = 1; } nq -= (int)(chk[there]==1)*2-1; } if (bt(nq,dep+1)) { grp[gn].push_back(v); chk[v] = -1; return true; } sel.pop_back(); chk[v] = -1; while(cand.size()>psz) { inc[cand.back()] = 0; cand.pop_back(); } cand.push_back(v); inc[v] = 1; return false; } void solve(int a, int b) { for (int &v : grp[a]) chk[v]++; for (int &v : grp[b]) chk[v]+=2; int c[2] = {0,0}; for (int &v : grp[a]) { 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<grp[t].size();i++) { if (chk[grp[t][i]]!=3) continue; swap(grp[t][i],grp[t].back()); grp[t].pop_back(); i--; } for (int &v : grp[a]) chk[v]=0; for (int &v : grp[b]) chk[v]=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; sel.clear(); cand.clear(); nop.clear(); sel.push_back(i); for (int &there : lis[i]) { cand.push_back(there); inc[there] = 1; } //printf("%d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",i); if (!bt(lis[i].size(),0)) pung(); else { grp[gn].push_back(i); chk[i] = -1; } for (int &there : lis[i]) inc[there] = 0; //printf("%d : ",i); //for (int &j : grp[i]) printf("%d ",j); //printf("\n"); 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 += (grp[i].size()>0); printf("%d\n",cnt); for (int i=0;i<n;i++) { if (grp[i].empty()) continue; printf("%d ",grp[i].size()); for (int &v : grp[i]) printf("%d ",v); printf("\n"); } /* */ return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 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 | 504 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 | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 11 ms | 1272 KB | Output is correct |
3 | Correct | 4 ms | 1144 KB | Output is correct |
4 | Correct | 4 ms | 1528 KB | Output is correct |
5 | Correct | 5 ms | 1528 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 888 KB | Output is correct |
8 | Correct | 22 ms | 1528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 11 ms | 1272 KB | Output is correct |
3 | Correct | 4 ms | 1144 KB | Output is correct |
4 | Correct | 4 ms | 1528 KB | Output is correct |
5 | Correct | 5 ms | 1528 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 888 KB | Output is correct |
8 | Correct | 22 ms | 1528 KB | Output is correct |
9 | Correct | 2 ms | 504 KB | Output is correct |
10 | Correct | 90 ms | 4664 KB | Output is correct |
11 | Correct | 84 ms | 5752 KB | Output is correct |
12 | Correct | 134 ms | 5624 KB | Output is correct |
13 | Correct | 139 ms | 5880 KB | Output is correct |
14 | Correct | 10 ms | 7900 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 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 | 504 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 | 504 KB | Output is correct |
9 | Correct | 2 ms | 504 KB | Output is correct |
10 | Correct | 11 ms | 1272 KB | Output is correct |
11 | Correct | 4 ms | 1144 KB | Output is correct |
12 | Correct | 4 ms | 1528 KB | Output is correct |
13 | Correct | 5 ms | 1528 KB | Output is correct |
14 | Correct | 2 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 888 KB | Output is correct |
16 | Correct | 22 ms | 1528 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 90 ms | 4664 KB | Output is correct |
19 | Correct | 84 ms | 5752 KB | Output is correct |
20 | Correct | 134 ms | 5624 KB | Output is correct |
21 | Correct | 139 ms | 5880 KB | Output is correct |
22 | Correct | 10 ms | 7900 KB | Output is correct |
23 | Correct | 2 ms | 504 KB | Output is correct |
24 | Correct | 2 ms | 504 KB | Output is correct |
25 | Correct | 2 ms | 504 KB | Output is correct |
26 | Correct | 99 ms | 8420 KB | Output is correct |
27 | Correct | 70 ms | 8016 KB | Output is correct |
28 | Correct | 113 ms | 7416 KB | Output is correct |
29 | Correct | 344 ms | 5112 KB | Output is correct |
30 | Correct | 54 ms | 5884 KB | Output is correct |
31 | Correct | 16 ms | 5880 KB | Output is correct |
32 | Correct | 2 ms | 504 KB | Output is correct |
33 | Execution timed out | 1085 ms | 11140 KB | Time limit exceeded |
34 | Halted | 0 ms | 0 KB | - |