AtCoder Regular Contest 082

Submission #1592030

Source codeソースコード

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
typedef long long i64;

int R[MAX_N], X, K, Q;

void get(i64 &temp) {
  if (temp < 0) temp = 0;
  if (temp > X) temp = X;
}

int main() {
  scanf("%d%d", &X, &K);
  for (int i = 1; i <= K; ++i)
    scanf("%d", &R[i]);

  scanf("%d", &Q);

  i64 sum = 0, mul = -1;
  i64 mn = 0, mx = X;
  int l = 1;
  
  while (Q--) {
    int T;
    i64 A;
    scanf("%d%lld", &T, &A);
    while (l <= K && R[l] <= T) {
      sum += (R[l] - R[l - 1]) * mul;
      mn += (R[l] - R[l - 1]) * mul;
      mx += (R[l] - R[l - 1]) * mul;
      get(mn), get(mx), mul = -mul;
      l++;
    }
    
    A += sum;
    if (A < mn) A = mn;
    if (A > mx) A = mx;
    A += (T - R[l - 1]) * mul;
    
    get(A);
    printf("%lld\n", A);
  }
  
  return 0;
}

Submission

Task問題 F - Sandglass
User nameユーザ名 kiiiiii
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 884 Byte
File nameファイル名
Exec time実行時間 47 ms
Memory usageメモリ使用量 1536 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &X, &K);
^
./Main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &R[i]);
^
./Main.cpp:21:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q);
^
./Main.cpp:30:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%lld", &T, &A);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
All 700 / 700 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt AC
0_001.txt AC
0_002.txt AC
1_003.txt AC 38 ms 768 KB
1_004.txt AC 40 ms 768 KB
1_005.txt AC 42 ms 768 KB
1_006.txt AC 37 ms 768 KB
1_007.txt AC 40 ms 768 KB
1_008.txt AC 42 ms 768 KB
1_009.txt AC 38 ms 768 KB
1_010.txt AC 40 ms 768 KB
1_011.txt AC 42 ms 896 KB
1_012.txt AC 38 ms 896 KB
1_013.txt AC 40 ms 896 KB
1_014.txt AC 44 ms 896 KB
1_015.txt AC 39 ms 1024 KB
1_016.txt AC 41 ms 1024 KB
1_017.txt AC 44 ms 1024 KB
1_018.txt AC 40 ms 1152 KB
1_019.txt AC 42 ms 1152 KB
1_020.txt AC 44 ms 1152 KB
1_021.txt AC 40 ms 1024 KB
1_022.txt AC 42 ms 1280 KB
1_023.txt AC 45 ms 1152 KB
1_024.txt AC 41 ms 1024 KB
1_025.txt AC 43 ms 1280 KB
1_026.txt AC 45 ms 1280 KB
1_027.txt AC 42 ms 1024 KB
1_028.txt AC 43 ms 1152 KB
1_029.txt AC 46 ms 1408 KB
1_030.txt AC 44 ms 1152 KB
1_031.txt AC 44 ms 1152 KB
1_032.txt AC 47 ms 1536 KB
1_033.txt AC 32 ms 1024 KB
1_034.txt AC 32 ms 896 KB
1_035.txt AC 44 ms 1280 KB
1_036.txt AC 34 ms 1024 KB
1_037.txt AC 34 ms 1024 KB
1_038.txt AC 46 ms 1408 KB
1_039.txt AC 34 ms 768 KB
1_040.txt AC 35 ms 1152 KB
1_041.txt AC 47 ms 1536 KB