結果
| 問題 | 
                            No.1687 What the Heck?
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-09-24 22:39:30 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 506 bytes | 
| コンパイル時間 | 867 ms | 
| コンパイル使用メモリ | 69,020 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-05 11:01:25 | 
| 合計ジャッジ時間 | 1,814 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 8 WA * 10 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:17: warning: 'I' may be used uninitialized [-Wmaybe-uninitialized]
   24 |                 if (i != I) {
      |                 ^~
main.cpp:16:13: note: 'I' was declared here
   16 |         int I;
      |             ^
            
            ソースコード
#include <iostream>
#include <vector>
typedef long long LL;
using namespace std;
int main()
{
	int N, i;
	cin >> N;
	if (N == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> P(N+1);
	LL take = 0;
	LL suzuki = 0;
	int I;
	for (i = 1; i <= N; i++) {
		cin >> P[i];
		if (P[i] == N) {
			I = i;
		}
	}
	for (i = 1; i <= N; i++) {
		if (i != I) {
			take += i;
		}
		else {
			suzuki += i;
		}
	}
	if (take - suzuki >= 0) {
		cout << take - suzuki << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}