# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659158 | 2022-11-16T19:37:59 Z | activedeltorre | Strange Device (APIO19_strange_device) | C++14 | 2995 ms | 282220 KB |
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; map<long long,long long>norm; vector<pair<long long,long long> >vec[2000005]; vector<pair<long long,long long > >complete; long long inf=1e18; bool cmp(pair<long long,long long> a,pair<long long,long long>b) { if(a.first!=b.first) { return a.first<b.first; } return a.second>b.second; } bool cmp2(pair<long long,long long> a,pair<long long,long long>b) { if(a.first!=b.first) { return a.first<b.first; } return a.second<b.second; } long long gcd(long long a , long b) { if(b==0) return a; a%=b; return gcd(b,a); } int main() { long long n,i,j,m,k,l,a,b,val1,val2,rest1,rest2,valoare,cnt=0,x,y,val3,val4,rest3,rest4,z; cin>>n>>a>>b; a=a/gcd(a,b+1); for(i=1; i<=n; i++) { cin>>x>>y; val1=x/b; val2=y/b; rest1=x%b; rest2=y%b; if(val2-val1>=2) { val3=val1/a; val4=val2/a; if(val3==val4) { complete.push_back({(val1+1)%a,(val2-1)%a}); } else if(val4==val3+1) { complete.push_back({(val1+1)%a,a-1}); complete.push_back({0,(val2-1)%a}); } else { complete.push_back({0,a-1}); } } if(val1==val2) { valoare=(val1)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({rest1,rest2}); complete.push_back({valoare,-1}); } else { ///adaug preim segmnt valoare=(val1)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({rest1,b-1}); complete.push_back({valoare,-1}); ///adaug al doilea segmnt valoare=(val2)%a; if(norm[valoare]==0) { cnt++; norm[valoare]=cnt; } vec[norm[valoare]].push_back({0,rest2}); complete.push_back({valoare,-1}); } } sort(complete.begin(),complete.end(),cmp); long long suma=0,nr,dr,index,maxim=-1,index2,lft,rgh,st; for(z=0; z<complete.size(); z++) { lft=complete[z].first; rgh=complete[z].second; if(rgh==-1 && (z==0 || complete[z-1].first!=lft)) { i=norm[lft]; sort(vec[i].begin(),vec[i].end(),cmp); nr=vec[i].size(); for(j=0; j<nr; j++) { index=j; st=vec[i][j].first; dr=vec[i][j].second; while(index+1<nr && dr>=vec[i][index+1].first) { dr=max(dr,vec[i][index+1].second); index++; } suma=suma+dr-st+1; j=index; } } else if(rgh!=-1) { index2=z; maxim=rgh; while(index2+1<complete.size() && maxim>=complete[index2+1].first) { if(complete[index2+1].second!=inf) { maxim=max(maxim,complete[index2+1].second); } index2++; } suma=suma+(maxim-lft+1)*b; z=index2; } } cout<<suma; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 47264 KB | Output is correct |
2 | Correct | 36 ms | 47716 KB | Output is correct |
3 | Correct | 34 ms | 47664 KB | Output is correct |
4 | Incorrect | 22 ms | 47176 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 47188 KB | Output is correct |
2 | Correct | 22 ms | 47188 KB | Output is correct |
3 | Correct | 24 ms | 47228 KB | Output is correct |
4 | Correct | 22 ms | 47164 KB | Output is correct |
5 | Correct | 23 ms | 47216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 47224 KB | Output is correct |
2 | Correct | 25 ms | 47344 KB | Output is correct |
3 | Correct | 24 ms | 47236 KB | Output is correct |
4 | Correct | 24 ms | 47296 KB | Output is correct |
5 | Correct | 1226 ms | 156740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 47188 KB | Output is correct |
2 | Correct | 1822 ms | 156812 KB | Output is correct |
3 | Correct | 2923 ms | 282220 KB | Output is correct |
4 | Correct | 2995 ms | 282124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 47188 KB | Output is correct |
2 | Correct | 1822 ms | 156812 KB | Output is correct |
3 | Correct | 2923 ms | 282220 KB | Output is correct |
4 | Correct | 2995 ms | 282124 KB | Output is correct |
5 | Correct | 24 ms | 47192 KB | Output is correct |
6 | Correct | 2538 ms | 203776 KB | Output is correct |
7 | Correct | 1623 ms | 109864 KB | Output is correct |
8 | Correct | 2371 ms | 203828 KB | Output is correct |
9 | Correct | 2892 ms | 203960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 47188 KB | Output is correct |
2 | Correct | 1822 ms | 156812 KB | Output is correct |
3 | Correct | 2923 ms | 282220 KB | Output is correct |
4 | Correct | 2995 ms | 282124 KB | Output is correct |
5 | Correct | 25 ms | 47188 KB | Output is correct |
6 | Correct | 219 ms | 62268 KB | Output is correct |
7 | Correct | 251 ms | 65956 KB | Output is correct |
8 | Correct | 244 ms | 65968 KB | Output is correct |
9 | Correct | 245 ms | 65932 KB | Output is correct |
10 | Correct | 214 ms | 59700 KB | Output is correct |
11 | Incorrect | 228 ms | 65932 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 47188 KB | Output is correct |
2 | Correct | 163 ms | 50836 KB | Output is correct |
3 | Correct | 176 ms | 50940 KB | Output is correct |
4 | Correct | 1952 ms | 126200 KB | Output is correct |
5 | Correct | 182 ms | 51900 KB | Output is correct |
6 | Correct | 180 ms | 51628 KB | Output is correct |
7 | Correct | 197 ms | 51756 KB | Output is correct |
8 | Correct | 192 ms | 53640 KB | Output is correct |
9 | Correct | 188 ms | 53880 KB | Output is correct |
10 | Correct | 161 ms | 50660 KB | Output is correct |
11 | Correct | 172 ms | 50764 KB | Output is correct |
12 | Correct | 161 ms | 50872 KB | Output is correct |
13 | Correct | 185 ms | 52784 KB | Output is correct |
14 | Correct | 1355 ms | 79224 KB | Output is correct |
15 | Correct | 165 ms | 51492 KB | Output is correct |
16 | Correct | 1357 ms | 79656 KB | Output is correct |
17 | Correct | 1767 ms | 121820 KB | Output is correct |
18 | Correct | 24 ms | 47264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 47264 KB | Output is correct |
2 | Correct | 36 ms | 47716 KB | Output is correct |
3 | Correct | 34 ms | 47664 KB | Output is correct |
4 | Incorrect | 22 ms | 47176 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |