๋ฌธ์ ๋งํฌ
10775๋ฒ: ๊ณตํญ (acmicpc.net)
10775๋ฒ: ๊ณตํญ
์์ 1 : [2][?][?][1] ํํ๋ก ๋ํน์ํฌ ์ ์๋ค. 3๋ฒ์งธ ๋นํ๊ธฐ๋ ๋ํน์ํฌ ์ ์๋ค. ์์ 2 : [1][2][3][?] ํํ๋ก ๋ํน ์ํฌ ์ ์๊ณ , 4๋ฒ์งธ ๋นํ๊ธฐ๋ ์ ๋ ๋ํน ์ํฌ ์ ์์ด์ ์ดํ ์ถ๊ฐ์ ์ธ ๋ํน์ ๋ถ
www.acmicpc.net
๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ด์ฉํด์ ํธ๋ ๋ฌธ์
ํ์ด ๊ณผ์
๋ณดํต ๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ๋ค์ ๋ณด๋ฉด ๋ฌด์์ ๊ธฐ์ค์ผ๋ก ์ฐ์ ์์๋ฅผ ์ ํ ์ง ์ฝ๊ฒ ์ ํ ์ ์๋ ๋ฌธ์ ๋ค์ด ๋ง์ง๋ง, ์ด ๋ฌธ์ ๋ ๋ช ํํ๋ค.
i๋ฒ์งธ ๋นํ๊ธฐ๋ 1 <= gi <= G ๋ฒ์งธ ๊ฒ์ดํธ ์ค ํ๋์ ๋ค์ด๊ฐ์ผํ๋ค. ์ด๋ค ๋นํ๊ธฐ๋ ์ง 1๋ฒ ๊ฒ์ดํธ์๋ ๋ค์ด๊ฐ ์ ์๋ค. ๋ฎ์ ๋ฒํธ์ ๊ฒ์ดํธ์ผ์๋ก ๋นํ๊ธฐ๊ฐ ๋ค์ด๊ฐ ์ ์์ ํ๋ฅ ์ด ๋๋ค.
์ฆ ๊ฒ์ดํธ ๋ฒํธ๊ฐ ์ต๋ํ ํฐ ๊ณณ๋ถํฐ ์ฑ์๋๊ฐ์ผ ๋ง์ ๋นํ๊ธฐ๋ฅผ ๊ฒ์ดํธ์ ๋ํนํ๊ธฐ์ ์ ๋ฆฌํ๋ค๋ ๊ฒ์ด๋ค.
๋ํน ๊ฐ๋ฅํ ๊ฐ์ฅ ํฐ ๋ฒํธ๋ฅผ ๋ฆฌํดํ๋ get_idx ํจ์๋ฅผ ๋ง๋ค์ด ์ฃผ์๋ค.
gi ๋ถํฐ ํ ๋ฒํธ์ฉ ๋ด๋ ค์ค๋ฉด์ ๋น์ด์๋ ๊ฒ์ดํธ์ ๋ฒํธ๋ฅผ ๋ฆฌํดํ๋ค. ๋ง์ฝ ๋น ๊ณต๊ฐ์ด ์์ด์ 0์ ๋ฆฌํดํ๋ค๋ฉด ์ด์ ๋์ด์ ๋นํ๊ธฐ๊ฐ ๋ชป๋ค์ด ๊ฐ๋ค๋ ๊ฒ์ด๋ฏ๋ก ๊ทธ๋๊น์ง ๋ค์ด๊ฐ ๋นํ๊ธฐ์ ์๊ฐ ๋ต์ด ๋๋ค.
ํ์ง๋ง ๋งค๋ฒ gi ๋ถํฐ ํ๋์ฉ ๋ด๋ ค์ค๋ฉด์ ๋ฒํธ๋ฅผ ์ฐพ๊ฒ๋๋ฉด ์๊ฐ์ด๊ณผ๊ฐ ๋ ์ ์๋ค. ๊ทธ๋์ section ์ด๋ผ๋ ๋ฐฐ์ด์ ๋ง๋ค์ด์ ๋นํ๊ธฐ๊ฐ ๊ฐ๋ ์ฐจ์๋ ๊ตฌ๊ฐ์ ์ ์ฅํด๋์๋ค. ๋ง์ฝ section[10] = 3 ์ด๋ผ๊ณ ํ๋ค๋ฉด 3๋ฒ๊ฒ์ดํธ๋ถํฐ 10๋ฒ๊ฒ์ดํธ๊น์ง๋ ๋นํ๊ธฐ๊ฐ ๋ชจ๋ ์ฐจ์๋ค๋ ๋ป์ด๋ค. gi = 11์ด๋ผ๊ณ ํ์. 11๋ฒ๊ฒ์ดํธ์ ์๋ฆฌ๊ฐ ์๋ ๊ฒ์ ํ์ธํ๊ณ 10๋ฒ๊ฒ์ดํธ๋ฅผ ํ์ํ๋๋ฐ section[10] = 3 ์ด๋ฏ๋ก 10 ~ 3๋ฒ๊ฒ์ดํธ๊น์ง๋ ๊ฐ๋์ฐฌ ๊ฒ์ ์ ์ ์๋ค. ๊ทธ๋ฌ๋ฏ๋ก ๋ฐ๋ก 2๋ฒ ๊ฒ์ดํธ๋ก๊ฐ์ ๋ค์ ํ์์ ์์ํ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <map>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef priority_queue<pair<pair<ll, int>, int>, vector<pair<pair<ll, int>, int>>, greater<pair<pair<ll, int>, int>>> Priority_queue;
const ll INF = LLONG_MAX;
const int MAX_N = 100000 + 5;
int G, P;
bool visited[MAX_N];
int section[MAX_N];
int get_idx(int num) {
int temp = num;
if (section[num] != -1) {
num = max(section[num]-1,0);
}
while(1) {
if (visited[num] == false) {
section[temp] = num;
break;
}
else if (section[num] != -1) {
num = max(section[num]-1,0);
}
else num--;
}
return num;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> G >> P;
memset(section, -1, sizeof(section));
int ans = 0;
for (int i = 1; i <= P; i++) {
int num;
cin >> num;
int idx = 0;
if (!ans) {
idx = get_idx(num);
if (!idx)
ans = i - 1;
if (idx && i == P)
ans = i;
visited[idx] = true;
}
}
cout << ans << "\n";
return 0;
}
|
cs |
์ฒซ ์๋๋ถํฐ 73ํผ์ผํธ๊น์ง ๊ฐ๋ฉด ๋ญ๊ฐ ํฌ๋ง์ ๋๋ผ๊ฒ ๋ผ์ ๋ ์ ํ๋ฆฌ๋ ๊ฒ ๊ฐ๋ค๐
'๋ฐฑ์ค > Gold' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] 15823 : ์นด๋ ํฉ ๊ตฌ๋งคํ๊ธฐ (0) | 2022.03.21 |
---|---|
[BOJ] 1700 : ๋ฉํฐํญ ์ค์ผ์ค๋ง (1) | 2022.03.17 |
[BOJ] 16236 : ์๊ธฐ ์์ด (0) | 2022.03.05 |
[BOJ] 2011 : ์ํธ์ฝ๋ (0) | 2022.03.03 |
[BOJ] 2225 : ํฉ๋ถํด (0) | 2022.03.02 |