Submission #662887

#TimeUsernameProblemLanguageResultExecution timeMemory
662887victor_gaoMonster Game (JOI21_monster)C++17
100 / 100
95 ms440 KiB
//#pragma GCC optimize("Ofast,unroll-loops,O3") //#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native") #include "monster.h" #include<bits/stdc++.h> #define pii pair<int,int> #define x first #define y second using namespace std; vector<int> Merge(vector<int>now){ if (now.size()<=1) return now; int n=now.size(); int mid=(n-1)/2; vector<int>l,r; for (int i=0;i<=mid;i++) l.push_back(now[i]); for (int i=mid+1;i<n;i++) r.push_back(now[i]); vector<int>al=Merge(l); vector<int>ar=Merge(r); vector<int>ans; int p=0; for (int i=0;i<al.size();i++){ if (p<ar.size()){ if (Query(al[i],ar[p])){ ans.push_back(ar[p]); p++; i--; } else ans.push_back(al[i]); } else ans.push_back(al[i]); } while (p<ar.size()){ ans.push_back(ar[p]); p++; } return ans; } int find(vector<int>all){ int n=min((int)all.size(),10),cnt[10]={0}; for (int i=0;i<n;i++){ for (int j=i+1;j<n;j++){ if (Query(all[i],all[j])) cnt[i]++; else cnt[j]++; } } vector<int>maybe; for (int i=0;i<n;i++){ if (cnt[i]==1) maybe.push_back(i); } if (maybe.size()==1) return maybe[0]; else { // cout<<all[maybe[0]]<<' '<<all[maybe[1]]<<'\n'; if (Query(all[maybe[0]],all[maybe[1]])) return maybe[0]; else return maybe[1]; } } vector<int> Solve(int N){ vector<int>now; for (int i=0;i<N;i++) now.push_back(i); vector<int>ans=Merge(now); /* for (auto i:ans) cout<<i<<" "; cout<<'\n'; for (auto i:ans) cout<<S[i]<<" "; cout<<'\n'; */ int pos=find(ans); //cout<<"find "<<pos<<'\n'; reverse(ans.begin(),ans.begin()+pos+1); for (int i=pos+1;i<N;i++){ if (Query(ans[pos],ans[i])){ reverse(ans.begin()+pos+1,ans.begin()+i+1); pos=i; } } if (pos<N) reverse(ans.begin()+pos+1,ans.begin()+N); vector<int>tans; tans.resize(N,0); for (int i=0;i<N;i++) tans[ans[i]]=i; return tans; }

Compilation message (stderr)

monster.cpp: In function 'std::vector<int> Merge(std::vector<int>)':
monster.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for (int i=0;i<al.size();i++){
      |                ~^~~~~~~~~~
monster.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (p<ar.size()){
      |         ~^~~~~~~~~~
monster.cpp:33:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while (p<ar.size()){
      |          ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...