提出 #39878658


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

int main(){
  long long L;
  int n1,n2;
  cin>>L>>n1>>n2;
  pair<int,long long>a[n1];
  pair<int,long long>b[n2];
  int anow=0;
  int bnow=0;
  for(int i=0;i<n1;i++){
    int v;
    long long l;  
    cin>>v>>l;
    a[i]={v,l};
  }
  for(int i=0;i<n2;i++){
    int v;
    long long l;  
    cin>>v>>l;
    b[i]={v,l};
  } 
  long long ans=0;
  while(1){
    if(anow==n1||bnow==n2) break;
    if(a[anow].first==b[bnow].first){
      if(a[anow].second==b[bnow].second){
        ans+=a[anow].second;
        anow++;
        bnow++;
        continue;
      }
      else if(a[anow].second<b[bnow].second){
        ans+=a[anow].second;
        b[bnow].second=b[bnow].second-a[anow].second;
        anow++;
      }
      else if(a[anow].second>b[bnow].second){
        ans+=b[bnow].second;
        a[anow].second=a[anow].second-b[bnow].second;
        bnow++;
      }    
    }
    else{
      if(a[anow].second==b[bnow].second){
        anow++;
        bnow++;
      }
      else if(a[anow].second>b[bnow].second){
          a[anow].second=a[anow].second-b[bnow].second;
          bnow++;
      }
      else{
        b[bnow].second=b[bnow].second-a[anow].second;
        anow++;
      }
    }
  }
  cout<<ans<<endl;     
}

提出情報

提出日時
問題 E - 2xN Grid
ユーザ chacoder
言語 C++ (GCC 9.2.1)
得点 500
コード長 1323 Byte
結果 AC
実行時間 113 ms
メモリ 6700 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 36
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 02_max_14.txt, 02_max_15.txt, 02_max_16.txt, 02_max_17.txt, 02_max_18.txt, 02_max_19.txt, 02_max_20.txt, 02_max_21.txt, 02_max_22.txt, 02_max_23.txt, 02_max_24.txt, 02_max_25.txt, 02_max_26.txt, 02_max_27.txt, 02_max_28.txt, 02_max_29.txt, 02_max_30.txt, 03_edge_31.txt, 03_edge_32.txt, 03_edge_33.txt, 03_edge_34.txt, 03_edge_35.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 15 ms 3512 KiB
00_sample_01.txt AC 2 ms 3356 KiB
00_sample_02.txt AC 2 ms 3592 KiB
01_random_03.txt AC 50 ms 4556 KiB
01_random_04.txt AC 91 ms 5936 KiB
01_random_05.txt AC 82 ms 5712 KiB
01_random_06.txt AC 71 ms 5500 KiB
01_random_07.txt AC 50 ms 4584 KiB
01_random_08.txt AC 54 ms 4836 KiB
01_random_09.txt AC 76 ms 5596 KiB
01_random_10.txt AC 78 ms 5772 KiB
01_random_11.txt AC 44 ms 4612 KiB
01_random_12.txt AC 30 ms 3980 KiB
01_random_13.txt AC 76 ms 5628 KiB
02_max_14.txt AC 111 ms 6672 KiB
02_max_15.txt AC 109 ms 6636 KiB
02_max_16.txt AC 108 ms 6676 KiB
02_max_17.txt AC 107 ms 6636 KiB
02_max_18.txt AC 108 ms 6516 KiB
02_max_19.txt AC 110 ms 6668 KiB
02_max_20.txt AC 108 ms 6700 KiB
02_max_21.txt AC 108 ms 6640 KiB
02_max_22.txt AC 108 ms 6644 KiB
02_max_23.txt AC 108 ms 6608 KiB
02_max_24.txt AC 109 ms 6484 KiB
02_max_25.txt AC 111 ms 6676 KiB
02_max_26.txt AC 108 ms 6696 KiB
02_max_27.txt AC 109 ms 6520 KiB
02_max_28.txt AC 109 ms 6648 KiB
02_max_29.txt AC 108 ms 6612 KiB
02_max_30.txt AC 113 ms 6636 KiB
03_edge_31.txt AC 16 ms 3760 KiB
03_edge_32.txt AC 15 ms 3608 KiB
03_edge_33.txt AC 2 ms 3512 KiB
03_edge_34.txt AC 2 ms 3552 KiB
03_edge_35.txt AC 106 ms 6648 KiB