Submission #468448

# Submission time Handle Problem Language Result Execution time Memory
468448 2021-08-28T10:56:11 Z Killer2501 Strange Device (APIO19_strange_device) C++14
15 / 100
220 ms 31196 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e18+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N];
vector<pll> adj[N], kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void sol()
{
    ll A, B;
    cin >> n >> A >> B;
    A /= __gcd(A, B+1);
    if(A > mod / B)tong = mod;
    else tong = A * B;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i] >> b[i];
        if(b[i]-a[i]+1 >= tong)
        {
            cout << tong;
            return;
        }
        a[i] %= tong;
        b[i] %= tong;
        if(a[i] <= b[i])kq.pb({a[i], b[i]});
        else
        {
            kq.pb({0, b[i]});
            kq.pb({a[i], tong-1});
        }
    }
    sort(kq.begin(), kq.end());
    ll l = kq[0].fi, r = kq[0].se;
    ans = r-l+1;
    for(int i = 1; i < kq.size(); i ++)
    {
        if(kq[i].fi > r)
        {
            ans += kq[i].se - kq[i].fi + 1;
            l = kq[i].fi;
            r = kq[i].se;
        }
        else
        {
            ans += max(0ll, kq[i].se-r);
            r = max(kq[i].se, r);
        }
    }
    cout << ans;
}
int main()
{
    if(fopen(task".in", "r"))
    {
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/

Compilation message

strange_device.cpp: In function 'void sol()':
strange_device.cpp:54: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]
   54 |     for(int i = 1; i < kq.size(); i ++)
      |                    ~~^~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:74:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:75:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 8 ms 5928 KB Output is correct
3 Correct 8 ms 5840 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 5028 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 8 ms 5932 KB Output is correct
17 Correct 55 ms 11892 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 4 ms 5040 KB Output is correct
5 Incorrect 144 ms 26108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Incorrect 180 ms 31196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Incorrect 180 ms 31196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Incorrect 180 ms 31196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 57 ms 11964 KB Output is correct
3 Correct 60 ms 11936 KB Output is correct
4 Incorrect 220 ms 31152 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 8 ms 5928 KB Output is correct
3 Correct 8 ms 5840 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 5028 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 8 ms 5932 KB Output is correct
17 Correct 55 ms 11892 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 5020 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 4 ms 5024 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5040 KB Output is correct
28 Incorrect 144 ms 26108 KB Output isn't correct