Submission #44956547


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
#define lcm(a, b) (a / gcd(a, b) * b) // 最小公倍数

typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int uint;
using namespace std;
// -------------------------------------

int main() {
	int N;
	vector<int> A;
	cin >> N;
	int a_sum = 0;
	int ans;
	rep(i, N) {
		int a;
		cin >> a;
		A.pb(a);
		a_sum += a;
	}

	sort(A.begin(), A.end());

	int prev = A[0];
	int nospace = true;
	for (int i = 1; i < A.size(); i++) {
		if ( prev + 1 != A[i] ) nospace = false;
		prev = A[i];
	}

	if (nospace) {
		if ( A[0] == 1 ) {
			cout << N + 1 << endl;
		} else if ( A[A.size() - 1] == 1000 ) {
			cout << A[0] - 1 << endl;
		}
	} else {
		// 間にある場合
		int Sn = (A[0] + A[A.size() - 1]) * (A.size() + 1) / 2;
		ans = Sn - a_sum;
		cout << ans << endl;
	}

	return 0;
}

Submission Info

Submission Time
Task B - MissingNo.
User saigo
Language C++ 20 (gcc 12.2)
Score 200
Code Size 1016 Byte
Status AC
Exec Time 1 ms
Memory 3656 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:31:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   31 |         for (int i = 1; i < A.size(); i++) {
      |                         ~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 17
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 1 ms 3472 KiB
random_02.txt AC 1 ms 3652 KiB
random_03.txt AC 1 ms 3468 KiB
random_04.txt AC 1 ms 3560 KiB
random_05.txt AC 1 ms 3372 KiB
random_06.txt AC 1 ms 3452 KiB
random_07.txt AC 1 ms 3656 KiB
random_08.txt AC 1 ms 3464 KiB
random_09.txt AC 1 ms 3468 KiB
random_10.txt AC 1 ms 3468 KiB
random_11.txt AC 1 ms 3460 KiB
random_12.txt AC 1 ms 3460 KiB
random_13.txt AC 1 ms 3520 KiB
random_14.txt AC 1 ms 3484 KiB
sample_01.txt AC 1 ms 3564 KiB
sample_02.txt AC 1 ms 3452 KiB
sample_03.txt AC 1 ms 3560 KiB