답안 #931922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931922 2024-02-22T14:41:39 Z 12345678 이상한 기계 (APIO19_strange_device) C++17
5 / 100
613 ms 115952 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=1e6+5;
ll n, a, b, l[nx], r[nx], sm, p, mx, res;
set<pair<ll, ll>> s;

void add_range(ll x, ll y)
{
    x=x%p;
    y=y%p;
    if (y<x) y+=p;
    s.insert({x, min(p-1, y)});
    if (y>=p) s.insert({0, y-p});
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>a>>b;
    p=a*b;
    for (int i=1; i<=n; i++) cin>>l[i]>>r[i], mx=max(mx, r[i]-l[i]+1), sm+=(r[i]-l[i]+1);
    if (a>LLONG_MAX/b) return cout<<0/0, 0;
    if (mx>=p) return cout<<p, 0;
    for (int i=1; i<=n; i++) add_range(l[i], r[i]);
    //for (auto [x, y]:s) cout<<"val "<<x<<' '<<y<<'\n';
    for (auto itr=s.begin(); itr!=s.end()&&next(itr)!=s.end();)
    {
        auto itr2=next(itr);
        pair<ll, ll> nw;
        if (itr2->first>itr->second+1) itr=itr2;
        else nw={itr->first, max(itr->second, itr2->second)}, s.erase(itr), s.erase(itr2), s.insert(nw), itr=s.find(nw);
    }
    for (auto [x, y]:s) res+=y-x+1;
    cout<<res;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:26:38: warning: division by zero [-Wdiv-by-zero]
   26 |     if (a>LLONG_MAX/b) return cout<<0/0, 0;
      |                                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 5 ms 3420 KB Output is correct
3 Correct 5 ms 3420 KB Output is correct
4 Incorrect 2 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Runtime error 3 ms 4700 KB Execution killed with signal 4
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2528 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 212 ms 41208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 523 ms 115684 KB Output is correct
3 Incorrect 561 ms 115952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 523 ms 115684 KB Output is correct
3 Incorrect 561 ms 115952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 523 ms 115684 KB Output is correct
3 Incorrect 561 ms 115952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2592 KB Output is correct
2 Correct 61 ms 16724 KB Output is correct
3 Correct 58 ms 16724 KB Output is correct
4 Correct 581 ms 115792 KB Output is correct
5 Correct 57 ms 16796 KB Output is correct
6 Correct 67 ms 16748 KB Output is correct
7 Correct 57 ms 16744 KB Output is correct
8 Correct 57 ms 16624 KB Output is correct
9 Correct 65 ms 16720 KB Output is correct
10 Correct 51 ms 16492 KB Output is correct
11 Correct 56 ms 16748 KB Output is correct
12 Correct 51 ms 16720 KB Output is correct
13 Correct 63 ms 16616 KB Output is correct
14 Correct 613 ms 115632 KB Output is correct
15 Incorrect 68 ms 16744 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 5 ms 3420 KB Output is correct
3 Correct 5 ms 3420 KB Output is correct
4 Incorrect 2 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -