Submission #338051

# Submission time Handle Problem Language Result Execution time Memory
338051 2020-12-22T11:19:15 Z Sho10 Strange Device (APIO19_strange_device) C++14
0 / 100
914 ms 100204 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a,b;
map<ll,ll>m;
int32_t main(){
CODE_START;
cin>>n>>a>>b;
ll ans=0;
ll MOD=log10(a) - log10(__gcd(a, b+1)) + log10(b) > 18 ? (long long)(1e18+1) : a / __gcd(a, b+1) * a;
while(n--){
    ll l,r;
    cin>>l>>r;
   ll L=l%MOD,R=r%MOD;
		if(r-l>=MOD) ans=MOD;
		else if (L<R) m[L]++,m[R+1]--;
		else if (L>R) m[L]++,m[MOD]--,m[0]++,m[R+1]--;
		else if (l==r) m[L]++,m[L+1]--;
		else ans=MOD;

}
ll sum=0,s1=1,l;
if(ans!=MOD){
    for(auto it : m){
        sum+=it.s;
        if(sum&&s1){
            l=it.f;
            s1=0;
        }else if(!sum){
        ans+=it.f-l;
        s1=1;
        }
    }
}
cout<<ans<<endl;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:47:18: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |         ans+=it.f-l;
      |              ~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 7 ms 1388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 914 ms 100204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 914 ms 100204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 914 ms 100204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 70 ms 10348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 7 ms 1388 KB Output isn't correct
3 Halted 0 ms 0 KB -