Submission #1044705

# Submission time Handle Problem Language Result Execution time Memory
1044705 2024-08-05T12:36:16 Z vjudge1 Strange Device (APIO19_strange_device) C++17
0 / 100
1 ms 348 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;


ll n, a, b;
vector<pair<ll, ll>> v;
void solve(){
  cin >> n >> a >> b;
  if(a > N || b > N || a*b > N) return;
  ll g = gcd(b+1, a);
  ll rep = b*a/g;
  ll ans = 0, pref = -1, suf = rep;
  for(int i = 1; i <= n; ++i){
    ll t1, t2; cin >> t1 >> t2;
    if(t1 + rep <= t2){
      ans = rep;
    }else{
      if(t2 % rep < t1 % rep){
        v.pb({0, t2 % rep});
        v.pb({t1 % rep, rep - 1});
      }else{
        v.pb({t1%rep, t2%rep});
      }
    }
  }
  if(ans == rep) cout << ans;
  else{
    sort(all(v));
    ll ans = rep;
    if(v.size() && v[0].ff > 0) ans -= v[0].ff;
    if(v.size() && v.back().ss < rep - 1) ans -= rep - v.back().ss - 1;
    for(int i = 1; i < v.size(); ++i){
      if(v[i].ff > v[i - 1].ss) ans -= v[i].ff - v[i - 1].ss - 1;
    }
    // for(auto p: v) cout << p.ff << ' ' << p.ss << '\n';
    cout << ans;
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 1; i < v.size(); ++i){
      |                    ~~^~~~~~~~~~
strange_device.cpp:22:15: warning: unused variable 'pref' [-Wunused-variable]
   22 |   ll ans = 0, pref = -1, suf = rep;
      |               ^~~~
strange_device.cpp:22:26: warning: unused variable 'suf' [-Wunused-variable]
   22 |   ll ans = 0, pref = -1, suf = rep;
      |                          ^~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:53:15: warning: unused variable 'aa' [-Wunused-variable]
   53 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -