Submission #403458

# Submission time Handle Problem Language Result Execution time Memory
403458 2021-05-13T07:54:50 Z Hazem Strange Device (APIO19_strange_device) C++14
0 / 100
4784 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 1e6+10;
const int M = 200;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

pair<LL,LL>p[N];
vector<pair<LL,LL>>vec;

LL gcd(LL a,LL b){return !b?a:gcd(b,a%b);}

int main(){

    //freopen("out.txt","w",stdout);

    LL n,a,b,Len;
    scanf("%lld%lld%lld",&n,&a,&b);

    // for(int i=0;i<=n;i++)
    //     printf("%d %d\n",(i+i/b)%a,i%b);

    b++;
    LL g = gcd(a,b);

    a /= g;

    if(log(a)+log(b)>=log(LLONG_MAX))    
        Len = LINF;
    else 
        Len = a*b-a;

    bool q = 0;
    set<LL>st;
    LL ans = 0;
    for(int i=1;i<=n;i++){

        scanf("%lld%lld",&p[i].F,&p[i].S);
        q |= p[i].S-p[i].F+1>=Len;

        p[i].F %= Len;p[i].S %= Len;
        
        for(int j=p[i].F;j<=p[i].S;j++)
            st.insert(j%Len);


        // if(p[i].F<=p[i].S)
        //     //ans += p[i].S-p[i].F+1;
        //  for(int j=p[i].F;j<=p[i].S;j++)
        //      st.insert(j);
        
        // else {
            
        //     //ans += Len-p[i].F;
        //      for(int j=p[i].F;j<=Len-1;j++)
        //          st.insert(j);
            
        //      for(int j=0;j<=p[i].S;j++)
        //          st.insert(j);
        //     //ans += p[i].S+1;
        // }

        if(p[i].S>=p[i].F)
            vec.push_back({p[i].F,p[i].S});
        else 
            vec.push_back({p[i].F,Len-1}),vec.push_back({0,p[i].S});
    }

    // sort(vec.begin(),vec.end());
    
    // LL l = 0,r = -1,ans = 0;
    // vec.push_back({LINF,LINF});

    // for(int i=0;i<vec.size();i++){
        
    //     if(vec[i].F>r)
    //         ans += r-l+1,l = vec[i].F,r = vec[i].S;
    //     else 
    //         r = vec[i].S;
    // }

    printf("%lld\n",q?Len:st.size());
}   

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:44:8: warning: unused variable 'ans' [-Wunused-variable]
   44 |     LL ans = 0;
      |        ^~~
strange_device.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%lld%lld%lld",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%lld%lld",&p[i].F,&p[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 46 ms 9980 KB Output is correct
3 Incorrect 66 ms 14120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 4784 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 113 ms 24220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 707 ms 78532 KB Output is correct
3 Runtime error 4281 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 707 ms 78532 KB Output is correct
3 Runtime error 4281 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 707 ms 78532 KB Output is correct
3 Runtime error 4281 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 2855 ms 524292 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 46 ms 9980 KB Output is correct
3 Incorrect 66 ms 14120 KB Output isn't correct
4 Halted 0 ms 0 KB -