Submission #243621

# Submission time Handle Problem Language Result Execution time Memory
243621 2020-07-01T12:32:15 Z uacoder123 Strange Device (APIO19_strange_device) C++14
0 / 100
544 ms 36164 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
 
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli test=1;
  for(;test>0;--test)
  {
    lli n,a,b,g,p,f,s,cl,cr,ans=0;
    cin>>n>>a>>b;
    g=__gcd(a,b+1);
    g=a/g;
    if(1.0*g*b>1e18)
      p=1e18;
    else
      p=g*b;
    vector<ii> v;
    for(lli i=0;i<n;++i)
    {
      cin>>f>>s;
      if(f-s+1>=p)
      {
        cout<<p<<endl;
        exit(0);
      }
      f%=p;
      s%=p;
      if(f<=s)
        v.pb(mp(f,s));
      else
      {
        v.pb(mp(0,s));
        v.pb(mp(f,p-1));
      }
    }
    sort(all(v));
    v.pb(mp(p,p));
    cl=0;
    cr=-1;
    ans=0;
    for(lli i=0;i<v.size();++i)
    {
      if(v[i].F<=cr&&v[i].S>=cr)
      {
        cr=v[i].S;
      }
      else
      {
        ans+=cr-cl+1;
        cl=v[i].F;
        cr=v[i].S;
      }
    }
    cout<<ans<<endl;
  }
  return(0);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli i=0;i<v.size();++i)
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 392 KB Output is correct
2 Incorrect 10 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 544 ms 36164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 544 ms 36164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 544 ms 36164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 58 ms 5776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 392 KB Output is correct
2 Incorrect 10 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -