답안 #513590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513590 2022-01-17T09:36:39 Z amukkalir 이상한 기계 (APIO19_strange_device) C++17
5 / 100
1112 ms 70432 KB
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define pii pair<int,int> 
#define pll pair<ll, ll> 
#define fi first 
#define se second 
#define pb push_back 
#define mp make_pair
 
int n, a, b; 
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b); 
}
 
signed main () {
    scanf("%d %d %d", &n, &a, &b); 

    vector<pll> v; 
    for(int i=0; i<n; i++) {
        ll l, r; scanf("%lld %lld", &l, &r); 
        v.pb(mp(l,r)); 
    }
    
    
    ll ans = 0; 
    //if r max < a*b / gcd(a, b+1)

    if(v.back().se / b < a / gcd(a, b+1)) { 
        for(int i=0; i<n; i++) {
            ans += v[i].se - v[i].fi + 1; 
        }
    } else {
        ll c = a/gcd(a, b+1) * b; 

        for(int i=0; i<n; i++) {
            if(v[i].se % c < v[i].fi % c || v[i].se >= v[i].fi + c) {
                v.pb(mp(0, v[i].se % c)); 
                v[i].se = c-1; 
            }

            v[i].fi %= c; 
            v[i].se %= c; 
        }

        sort(v.begin(), v.end(), [&] (pll a, pll b) {
            if(a.fi % c == b.fi % c) return a.se % c < b.se % c; 
            return a.fi % c < b.fi % c; 
        }); 

        //for(auto p : v) cout << p.fi << " " << p.se << endl; 
        for(int i=0; i<v.size(); i++) {
            int l = i, r = i; 
            while(r + 1 < v.size() && v[r+1].fi <= v[r].se)  r++; 
            //cout << " :: " << l << " " << r << endl; 
            ans += v[r].se - v[l].fi + 1; 
            
            i = r; 
        }
    }

    printf("%lld", ans); 
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:52:23: 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]
   52 |         for(int i=0; i<v.size(); i++) {
      |                      ~^~~~~~~~~
strange_device.cpp:54:25: 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 |             while(r + 1 < v.size() && v[r+1].fi <= v[r].se)  r++;
      |                   ~~~~~~^~~~~~~~~~
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d %d", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:21:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         ll l, r; scanf("%lld %lld", &l, &r);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 8 ms 1004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 749 ms 53136 KB Output is correct
3 Incorrect 1112 ms 70432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 749 ms 53136 KB Output is correct
3 Incorrect 1112 ms 70432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 749 ms 53136 KB Output is correct
3 Incorrect 1112 ms 70432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 89 ms 5644 KB Output is correct
3 Incorrect 58 ms 5596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 8 ms 1004 KB Output isn't correct
3 Halted 0 ms 0 KB -