結果

問題 No.561 東京と京都
ユーザー pinebookspinebooks
提出日時 2017-08-25 23:16:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 796 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 49,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 15:43:59
合計ジャッジ時間 1,107 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   scanf("%d%d", &N, &D);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     scanf("%d%d", &ti, &ki);
      |     ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main() {
  int N, D;
  scanf("%d%d", &N, &D);
  vector<int> T, K;
  for (int i = 0; i < N; ++i) {
    int ti, ki;
    scanf("%d%d", &ti, &ki);
    T.push_back(ti);
    K.push_back(ki);
  }
  string current_location = "Tokyo";
  int real_tokyo_payment;
  int real_kyoto_payment;
  int salary = 0;
  for (int i = 0; i < N; ++i) {
    real_tokyo_payment = current_location == "Tokyo" ? T[i] : T[i] - D;
    real_kyoto_payment = current_location == "Kyoto" ? K[i] : K[i] - D;
    if (real_tokyo_payment >= real_kyoto_payment) {
      salary += real_tokyo_payment;
      current_location = "Tokyo";
    } else {
      salary += real_kyoto_payment;
      current_location = "Kyoto";
    }
  }
  printf("%d\n", salary);
}
0