Submission #986569

#TimeUsernameProblemLanguageResultExecution timeMemory
986569activedeltorreInterval Collection (CCO20_day2problem2)C++14
3 / 25
7069 ms616 KiB
#include <iostream> #include <vector> using namespace std; struct ura { int a,b; }; vector<ura>vec; int inter(int i,int j) { return max(0,min(vec[i].b,vec[j].b)-max(vec[i].a,vec[j].a)); } int reun(int i,int j) { return max(vec[i].b,vec[j].b)-min(vec[i].a,vec[j].a); } int main() { int n,i,j,k,l,r,z; cin>>n; char tip; for(i=1;i<=n;i++) { cin>>tip; if(tip=='A') { cin>>l>>r; vec.push_back({l,r}); } else if(tip=='R') { cin>>l>>r; for(j=0;j<vec.size();j++) { if(vec[j].a==l && vec[j].b==r) { vec.erase(vec.begin()+j); break; } } } int minim=1e9,sol; for(j=0;j<vec.size();j++) { for(z=j;z<vec.size();z++) { if(inter(z,j)<minim) { minim=inter(z,j); sol=reun(z,j); } else if(inter(z,j)==minim) { sol=min(sol,reun(z,j)); } } } cout<<sol<<'\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for(j=0;j<vec.size();j++)
      |                     ~^~~~~~~~~~~
Main.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(j=0;j<vec.size();j++)
      |                 ~^~~~~~~~~~~
Main.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for(z=j;z<vec.size();z++)
      |                     ~^~~~~~~~~~~
Main.cpp:21:15: warning: unused variable 'k' [-Wunused-variable]
   21 |     int n,i,j,k,l,r,z;
      |               ^
Main.cpp:60:20: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |         cout<<sol<<'\n';
      |                    ^~~~
#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...