結果

問題 No.1650 Moving Coins
ユーザー LayCurseLayCurse
提出日時 2021-08-20 23:18:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 4,377 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 218,476 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2024-04-22 07:41:48
合計ジャッジ時間 6,657 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
7,628 KB
testcase_03 AC 5 ms
6,948 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
7,112 KB
testcase_08 AC 10 ms
8,136 KB
testcase_09 AC 10 ms
7,620 KB
testcase_10 AC 11 ms
7,876 KB
testcase_11 AC 11 ms
8,004 KB
testcase_12 AC 8 ms
7,936 KB
testcase_13 AC 9 ms
7,752 KB
testcase_14 AC 11 ms
8,136 KB
testcase_15 AC 8 ms
7,820 KB
testcase_16 AC 12 ms
7,876 KB
testcase_17 AC 12 ms
8,132 KB
testcase_18 AC 11 ms
8,008 KB
testcase_19 AC 13 ms
8,008 KB
testcase_20 AC 13 ms
8,008 KB
testcase_21 AC 13 ms
8,008 KB
testcase_22 AC 14 ms
8,136 KB
testcase_23 AC 14 ms
8,032 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 4 ms
6,984 KB
testcase_26 AC 8 ms
7,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline int arrcmp(int As, S A[], int Bs, T B[]){
  int i;
  for(i=0;;i++){
    if(i==As && As==Bs){
      break;
    }
    if(i==As){
      return -1;
    }
    if(i==Bs){
      return 1;
    }
    if(A[i] < B[i]){
      return -1;
    }
    if(A[i] > B[i]){
      return 1;
    }
  }
  return 0;
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
int N;
int A[200000];
int B[200000];
int M;
int K[200000];
char C[200000];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){
      rd(B[e98WHCEY]);
    }
  }
  while(arrcmp(N,A,N,B)){
    int i;
    for(i=(N)-1;i>=(0);i--){
      while(A[i] < B[i] && (i==N-1 || A[i]+1 < A[i+1])){
        A[i]++;
        arrInsert(M,M,K,i,C,'R');
      }
    }
    for(i=(0);i<(N);i++){
      while(A[i] > B[i] && (i==0 || A[i]-1 > A[i-1])){
        A[i]--;
        arrInsert(M,M,K,i,C,'L');
      }
    }
  }
  wt_L(M);
  wt_L('\n');
  for(i=(0);i<(M);i++){
    wt_L(K[i]+1);
    wt_L(' ');
    wt_L(C[i]);
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210819-1 [beta]

// --- original code ---
// int N, A[2d5], B[2d5];
// int M, K[]; char C[];
// {
//   rd(N,A(N),B(N));
//   while(arrcmp(N,A,N,B)){
//     rrep(i,N) while(A[i] < B[i] && (i==N-1 || A[i]+1 < A[i+1])){
//       A[i]++;
//       arrInsert(M,M,K,i,C,'R');
//     }
//     rep(i,N) while(A[i] > B[i] && (i==0 || A[i]-1 > A[i-1])){
//       A[i]--;
//       arrInsert(M,M,K,i,C,'L');
//     }
//   }
//   wt(M);
//   rep(i,M) wt(K[i]+1, C[i]);
// }
0