結果

問題 No.633 バスの運賃
ユーザー GBGB
提出日時 2018-09-17 18:47:23
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 118,656 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 17:51:05
合計ジャッジ時間 1,085 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:2: warning: 'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'? [-Wmismatched-new-delete]
   32 |         delete bus_stop;
      |         ^
      |               []
main.cpp:11:18: note: allocated with 'new[]' here
   11 |         int* bus_stop = new int[n-1];
      |                         ^
main.cpp:33:2: warning: 'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'? [-Wmismatched-new-delete]
   33 |         delete b;
      |         ^
      |               []
main.cpp:13:11: note: allocated with 'new[]' here
   13 |         int *b = new int[n];
      |                  ^
main.cpp:34:2: warning: 'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'? [-Wmismatched-new-delete]
   34 |         delete c;
      |         ^
      |               []
main.cpp:14:11: note: allocated with 'new[]' here
   14 |         int *c = new int[n];
      |                  ^
3 warnings generated.

ソースコード

diff #

#include<iostream>

using namespace std;

int main() {

	int n;

	cin >> n;

	int* bus_stop = new int[n-1];
	int ans = 0;
	int *b = new int[n];
	int *c = new int[n];

	for (int i = 0;i < n - 1;i++) {
		cin >> bus_stop[i];
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i] >> c[i];
	}

	int sumc=0, sumb=0;
	for (int i = 0;i < n - 1;i++) {
		sumc += c[i],sumb+=b[i];
		ans += (sumc - sumb)*bus_stop[i];
	}

	cout << ans << endl;


	delete bus_stop;
	delete b;
	delete c;

	return 0;
}
0