Submission #781654

# Submission time Handle Problem Language Result Execution time Memory
781654 2023-07-13T09:13:01 Z christinelynn Strange Device (APIO19_strange_device) C++17
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
const int MAX=1e18;
signed main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  assert(0);
  int n, a, b; cin >> n >> a >> b;
    priority_queue<pii, vector<pii>, greater<pii>> pq, to_ans;
    while(n--) {
      int l, r; cin >> l >> r;
      pq.push({l, r});
    }
    int Mod;
    if(a>(MAX+b-1)/b) Mod=1e18+1;
    else Mod=a*b;
    while(!pq.empty()) {
      int l=pq.top().first, r=pq.top().second;
      pq.pop();
      while(!pq.empty() && pq.top().first<=r) r=max(r, pq.top().second), pq.pop();
    if((l+Mod-1)/Mod*Mod+Mod-1<=r) {cout << Mod << '\n'; return 0;}
      if((l+Mod-1)/Mod*Mod<=r && l%Mod) to_ans.push({l%Mod, Mod-1}), to_ans.push({0, r%Mod});
      else to_ans.push({l%Mod, r%Mod});
    }
    int ans=0;
    while(!to_ans.empty()) {
      int l=to_ans.top().first, r=to_ans.top().second;
      to_ans.pop();
      while(!to_ans.empty() && to_ans.top().first<=r) r=max(r, to_ans.top().second), to_ans.pop(); 
    ans+=r-l+1;
  }
  cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -