Submission #574706

#TimeUsernameProblemLanguageResultExecution timeMemory
574706KrisjanisPHandcrafted Gift (IOI20_gift)C++14
10 / 100
183 ms28712 KiB
#include "gift.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> ii; void compress(vector<ii>& one) { sort(one.begin(),one.end()); vector<ii> newOne; newOne.push_back(one[0]); for(ll i=1;i<one.size();i++) { if(one[i].first<=newOne.back().second) newOne.back().second=max(newOne.back().second,one[i].second); else newOne.push_back(one[i]); } one = newOne; } int construct(int n, int r, std::vector<int> a, std::vector<int> b, std::vector<int> x) { vector<ii> one, two; for(ll i=0;i<r;i++) { if(x[i]==1) one.push_back({a[i],b[i]}); else two.push_back({a[i],b[i]}); } compress(one); vector<bool> same(n,false); for(ll i=0;i<one.size();i++) { for(ll j=one[i].first+1;j<=one[i].second;j++) same[j]=true; } vector<ll> vec(n,0); vec[0]=0; for(ll i=1;i<n;i++) { if(same[i]) vec[i]=vec[i-1]; else vec[i]=1-vec[i-1]; } vector<ll> ps(n,0); ps[0]=vec[0]; for(ll i=1;i<n;i++) ps[i]=ps[i-1]+vec[i]; bool found = false; for(ll i=0;i<two.size();i++) { ll sum = ps[two[i].second]; if(two[i].first) sum-=ps[two[i].first]; if(sum==0||sum==(two[i].second-two[i].first+1)) { found=true; break; } } if(found) return 0; // answer doesn't exist std::string res(n, 'R'); for(ll i=0;i<n;i++) if(vec[i]) res[i]='B'; craft(res); return 1; }

Compilation message (stderr)

gift.cpp: In function 'void compress(std::vector<std::pair<long long int, long long int> >&)':
gift.cpp:12:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(ll i=1;i<one.size();i++)
      |                ~^~~~~~~~~~~
gift.cpp: In function 'int construct(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
gift.cpp:31:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(ll i=0;i<one.size();i++)
      |                ~^~~~~~~~~~~
gift.cpp:46:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(ll i=0;i<two.size();i++)
      |                ~^~~~~~~~~~~
#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...