답안 #404975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404975 2021-05-15T12:27:05 Z A_D 이상한 기계 (APIO19_strange_device) C++14
10 / 100
539 ms 53220 KB
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=1e6+100;
ii a[N];
vector<int> l;
vector<int> r;
vector<ii> b;
set<ii> st;
void solve()
{
    int n,A,B;
    cin>>n>>A>>B;
    int u=A*B;
    int m=A/2;
    if(A%2)m=u;
//    cout<<5<<endl;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i].F);
        scanf("%lld",&a[i].S);
        a[i].F%=u;
        a[i].S%=u;
        a[i].F%=m;
        a[i].S%=m;
//        cout<<a[i].F<<" "<<a[i].S<<endl;
        if(a[i].S<a[i].F){
            b.push_back({a[i].F,m-1});
            b.push_back({(int)0,a[i].S});
        }
        else{
            b.push_back({a[i].F,a[i].S});
        }
    }
    sort(b.begin(),b.end());
//    cout<<5<<endl;
    l.push_back(b[0].F);
    r.push_back(b[0].S);
    for(int i=1;i<b.size();i++){
  //      cout<<b[i].F<<" "<<b[i].S<<endl;
        int ll=l.back();
        int rr=r.back();
        if(!(ll>b[i].S||rr<b[i].F)){
    //        cout<<ll<<" "<<rr<<" "<<b[i].F<<" "<<b[i].S<<endl;
            l.pop_back();
            r.pop_back();
            l.push_back(min(ll,b[i].F));
            r.push_back(max(rr,b[i].S));
        }
        else{
            l.push_back(b[i].F);
            r.push_back(b[i].S);
        }
    }
//    cout<<"\n\n";
  //  for(int i=0;i<l.size();i++)cout<<l[i]<<" "<<r[i]<<endl;
    //cout<<"\n\n";
    int ans=0;
    for(int j=0;j<l.size();j++){
//        cout<<l[j]<<" "<<r[j]<<endl;
        ans+=r[j]-l[j]+1;
    }
  //  cout<<"\n\n";
//    cout<<st.size()<<endl;
    cout<<ans<<endl;
}

main()
{
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long 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<b.size();i++){
      |                 ~^~~~~~~~~
strange_device.cpp:62:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int j=0;j<l.size();j++){
      |                 ~^~~~~~~~~
strange_device.cpp: At global scope:
strange_device.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main()
      | ^~~~
strange_device.cpp: In function 'void solve()':
strange_device.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%lld",&a[i].F);
      |         ~~~~~^~~~~~~~~~~~~~~~
strange_device.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%lld",&a[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 6 ms 716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 381 ms 31628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 537 ms 53220 KB Output is correct
3 Correct 519 ms 53060 KB Output is correct
4 Correct 520 ms 53152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 537 ms 53220 KB Output is correct
3 Correct 519 ms 53060 KB Output is correct
4 Correct 520 ms 53152 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 531 ms 53132 KB Output is correct
7 Correct 539 ms 53160 KB Output is correct
8 Incorrect 533 ms 53048 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 537 ms 53220 KB Output is correct
3 Correct 519 ms 53060 KB Output is correct
4 Correct 520 ms 53152 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 52 ms 3896 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 56 ms 6340 KB Output is correct
3 Incorrect 62 ms 6028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 6 ms 716 KB Output isn't correct
3 Halted 0 ms 0 KB -