Submission #618

#TimeUsernameProblemLanguageResultExecution timeMemory
618gs13068지도 색칠하기 (GA3_map)C++98
85 / 120
1500 ms952 KiB
#include<vector> #include<set> #include<cstdio> std::vector<int> graph[20]; std::vector<int> group[20]; struct pair { int a; int b; int c; } temp,te; bool operator <(const pair &a,const pair &b) { if(a.a!=b.a)return a.a>b.a; if(a.b!=b.b)return a.b>b.b; return a.c<b.c; } int A[20]; int B[20]; bool erased[20]; int pos[20]; int color[20]; std::set<pair> s; inline long long Number(int x,int y) { if(y==group[x].size())return 1; int i; long long res=0; bool a,b,c,d; a=b=c=d=true; for(i=0;i<graph[group[x][y]].size();i++) { if(pos[graph[group[x][y]][i]]<pos[group[x][y]]) { if(color[graph[group[x][y]][i]]==1)a=false; else if(color[graph[group[x][y]][i]]==2)b=false; else if(color[graph[group[x][y]][i]]==3)c=false; else d=false; } } if(a){color[group[x][y]]=1;res+=Number(x,y+1);} if(b){color[group[x][y]]=2;res+=Number(x,y+1);} if(c){color[group[x][y]]=3;res+=Number(x,y+1);} if(d){color[group[x][y]]=4;res+=Number(x,y+1);} return res; } long long NumberOfMaps(int n, int m, int *a, int *b) { long long res=1; int i,j,cnt; for(i=0;i<m;i++){graph[a[i]-1].push_back(b[i]-1);graph[b[i]-1].push_back(a[i]-1);} for(i=0;i<n;i++){A[i]=temp.a=0;B[i]=temp.b=graph[i].size();temp.c=i;s.insert(temp);erased[i]=false;} for(cnt=0;!s.empty();cnt++) { do { temp=*s.begin(); s.erase(s.begin()); pos[temp.c]=group[cnt].size(); group[cnt].push_back(temp.c); erased[temp.c]=true; for(i=0;i<graph[temp.c].size();i++) { if(erased[graph[temp.c][i]])continue; te.a=A[graph[temp.c][i]]; te.b=B[graph[temp.c][i]]; te.c=graph[temp.c][i]; s.erase(s.find(te)); A[graph[temp.c][i]]++; B[graph[temp.c][i]]--; te.a++; te.b--; s.insert(te); } }while(s.begin()->a); } for(i=0;i<cnt;i++) { if(group[i].size()==1)res*=4; else if(group[i].size()==2)res*=12; else { color[group[i][0]]=1; color[group[i][1]]=2; res*=Number(i,2)*12; } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...