728x90
문제 링크: https://www.acmicpc.net/problem/15719
15719번: 중복된 숫자
1부터 N - 1까지의 정수가 하나씩 정렬되지 않은 채로 저장되어 있는 어떤 수열 A가 있다. 수열 A에 임의의 정수 M(1 ≤ M ≤ N – 1)을 넣어 크기가 N인 수열로 만들었을 때, 임의의 정수 M을 찾는 프
www.acmicpc.net
문제 풀이
반복문을 돌려 0부터 n-1까지 더하고 입력받은 숫자를 빼서 그 값에 절댓값을 씌워주면 된다.
이 문제는 파이썬을 이용하면 메모리 초과가 난다. sys.stdin.read를 해서 풀려고 했다가.. 그냥 귀찮아서 안했다.
코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
cin.tie(0); | |
ios_base::sync_with_stdio(0); | |
int n, s = 0; | |
cin >> n; | |
for (int i = 0; i < n; i++){ | |
s += i; | |
int x; | |
cin >> x; | |
s -= x; | |
} | |
cout << -s; | |
} |
728x90
'BOJ' 카테고리의 다른 글
[BOJ][C++] 백준 11098번 - 첼시를 도와줘! (0) | 2022.03.31 |
---|---|
[BOJ][C++] 백준 5800번 - 성적 통계 (0) | 2022.03.31 |
[BOJ][Python] 백준 1013번 - Contact (0) | 2022.03.30 |
[BOJ][Python] 백준 24513번 - 좀비 바이러스 (0) | 2022.03.30 |
[BOJ][C++] 백준 24860번 - Counting Antibodies (0) | 2022.03.29 |