Submission #1602504


Source Code Expand

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>

using namespace std;

/*
  let's try computer shogi!!!
 */

struct hinge{
  long long int s; // スタート
  long long int t; // 終わり
  long long int h; // 曲がるタイミング
};

const long long int zero = 0;
long long int X;
long long int K;
vector< long long int> r;
vector<hinge> h;

long long int Q;
vector< long long int> t;
vector< long long int> a;

int main(){
  cin >> X;
  cin >> K;
  r.resize(K);
  h.resize(K+1);
  
  h[0].s = zero;
  h[0].t = X;
  h[0].h = zero;
  
  for( long long int i=0;i<K;++i){
    cin >> r[i];
  }
  r.push_back(1145141919);
  cin >> Q;
  t.resize(Q);
  a.resize(Q);
  for( long long int i=0;i<Q;++i){
    cin >> t[i];
    cin >> a[i];
  }
  
  long long int nt = 0;
  long long int qcnt = 0;
  
  for( long long int i=0;i<K+1;++i){
    long long int dt = r[i] - nt;
    
     while(nt <= t[qcnt] && t[qcnt] <= r[i] && qcnt <Q){
       long long int sand = ( a[qcnt] < h[i].h ? h[i].s : min(h[i].s + a[qcnt]-h[i].h, h[i].t));
       cerr<<nt<<","<<t[qcnt]<<","<<r[i]<<","<<i<<","<<sand<<" (nt,t,r,i,sand)"<<endl;
       if(i%2==0){
	 cout<<max(sand-(t[qcnt]-nt),zero)<<endl;
       }else{
	 cout<<min(X,sand+(t[qcnt]-nt))<<endl;
       }
       qcnt++;
     }
     
     if(i==K){continue;}
     cerr<<dt<<"(dt)"<<endl;
     if(i%2==0){
       h[i+1].s = max(h[i].s - dt,zero);
       h[i+1].t = max(h[i].t - dt,zero);
       h[i+1].h = h[i].h + max(zero, (dt - h[i].s));
     }else{
       h[i+1].s = min(X,h[i].s + dt);
       h[i+1].t = min(X,h[i].t + dt);
       h[i+1].h = h[i].h;
     }
     cerr<<h[i+1].s<<","<<h[i+1].t<<","<<h[i+1].h<<"(sth)"<<endl;
     nt = r[i];
  }
}

Submission Info

Submission Time
Task F - Sandglass
User qhapaq_49
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1798 Byte
Status AC
Exec Time 1152 ms
Memory 7280 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1068 ms 5104 KB
1_004.txt AC 1071 ms 5104 KB
1_005.txt AC 1085 ms 5104 KB
1_006.txt AC 1066 ms 5104 KB
1_007.txt AC 1076 ms 5232 KB
1_008.txt AC 1094 ms 5232 KB
1_009.txt AC 1057 ms 5232 KB
1_010.txt AC 1069 ms 5232 KB
1_011.txt AC 1082 ms 5232 KB
1_012.txt AC 1069 ms 5360 KB
1_013.txt AC 1074 ms 5360 KB
1_014.txt AC 1091 ms 5232 KB
1_015.txt AC 1071 ms 7280 KB
1_016.txt AC 1080 ms 5360 KB
1_017.txt AC 1093 ms 5360 KB
1_018.txt AC 1080 ms 5488 KB
1_019.txt AC 1077 ms 5488 KB
1_020.txt AC 1092 ms 5488 KB
1_021.txt AC 1080 ms 5488 KB
1_022.txt AC 1089 ms 5616 KB
1_023.txt AC 1111 ms 5616 KB
1_024.txt AC 1138 ms 5360 KB
1_025.txt AC 1102 ms 5744 KB
1_026.txt AC 1112 ms 5744 KB
1_027.txt AC 1084 ms 5488 KB
1_028.txt AC 1101 ms 5488 KB
1_029.txt AC 1120 ms 5744 KB
1_030.txt AC 1152 ms 5488 KB
1_031.txt AC 1102 ms 5488 KB
1_032.txt AC 1108 ms 5872 KB
1_033.txt AC 662 ms 2688 KB
1_034.txt AC 671 ms 2560 KB
1_035.txt AC 1092 ms 7028 KB
1_036.txt AC 666 ms 2688 KB
1_037.txt AC 672 ms 2688 KB
1_038.txt AC 1100 ms 5744 KB
1_039.txt AC 676 ms 2432 KB
1_040.txt AC 682 ms 2816 KB
1_041.txt AC 1106 ms 5872 KB