๋ฌธ์ ๋งํฌ
20056๋ฒ: ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด๋ณผ (acmicpc.net)
20056๋ฒ: ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด๋ณผ
์ฒซ์งธ ์ค์ N, M, K๊ฐ ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ M๊ฐ์ ์ค์ ํ์ด์ด๋ณผ์ ์ ๋ณด๊ฐ ํ ์ค์ ํ๋์ฉ ์ฃผ์ด์ง๋ค. ํ์ด์ด๋ณผ์ ์ ๋ณด๋ ๋ค์ฏ ์ ์ ri, ci, mi, si, di๋ก ์ด๋ฃจ์ด์ ธ ์๋ค. ์๋ก ๋ค๋ฅธ ๋ ํ์ด์ด๋ณผ์ ์์น
www.acmicpc.net
๋ง๋ฒ์ฌ๊ฐ ๋ ์์ด๊ฐ ํ์ด์ด๋ณผ์ ๋ด๋ฆฐ ๋ช ๋ น์ ๊ตฌํํ๋ ๋ฌธ์ .
์ด์ ์ ํ์๋ ์๊ธฐ์์ด ๋ฌธ์ ์ ์ฐ๊ด ๋ฌธ์ ์ธ ๊ฒ๊ฐ๋ค.
ํ์ด
ํ์ด์ด๋ณผ์ ํฌ๊ธฐ๊ฐ N x N์ธ ๊ฒฉ์์์ ์์ง์ด๋ฉฐ 1๋ฒ ํ๊ณผ ์ด์ ๊ฐ๊ฐ N๋ฒ ํ๊ณผ ์ด๊ณผ ์ฐ๊ฒฐ๋์ด์๋ค. ์ฆ ํ์ด์ด๋ณผ์ด ๊ฒฉ์ ๋ฐ์ผ๋ก ๋๊ฐ๋ ์ผ์ ์๋ค.
๋ชจ๋ ํ์ด์ด๋ณผ์ ๋ช ๋ น 1๋ฒ๋น 1ํ์ฉ ์ด๋ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ ํ ํ ์นธ์ ์ฌ๋ฌ๊ฐ์ ํ์ด์ด๋ณผ์ด ์์ผ๋ฉด ํฉ์ณ์ก๋ค๊ฐ 4๊ฐ์ ํ์ด์ด๋ณผ๋ก ๋ถํ ๋๋ค.
๋ด๊ฐ ์ ์ฅํด์ผํ ์ ๋ณด๋
โ . ํ์ด์ด๋ณผ๋ค์ ๋ํ ์ ๋ณด
โก. ๊ฐ ์นธ์ ์ด๋ ํ์ด์ด๋ณผ์ด ๋ค์ด์๋์ง์ ๋ํ ์ ๋ณด
=> ๊ฐ ์นธ์ ๋ค์ด์๋ ํ์ด์ด๋ณผ์ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅํด๋์๋ค.
๋ง์ฝ ์์์ ์นธ์ ๋ค์ด์๋ ํ์ด์ด๋ณผ์ด 2๊ฐ์ด์์ด๋ฉด ์ด ์นธ์ ์๋ ํ์ด์ด๋ณผ์ ๋ถํ ๋์ด์ผํ๋ค.
โ . ํ์ด์ด๋ณผ๋ค์ ๋ํ ์ ๋ณด๋ ๋๋ vector<pair<pair<int, int>, pair<int, pair<int, int>>>> Fireball; ์ด๋ ๊ฒ
โก. ๊ฐ ์นธ์ ๋ค์ด์๋ ํ์ด์ด๋ณผ์ ๋ํ ์ ๋ณด๋
vector<int> Map[MAX_N][MAX_N] ์ด๋ ๊ฒ Map์ด๋ผ๋ ๋ฒกํฐ 2์ฐจ์๋ฐฐ์ด์ ์ ์ธํด์ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค.
1. ๋ชจ๋ ํ์ด์ด๋ณผ์ด ์์ ์ ๋ฐฉํฅ di๋ก ์๋ ฅ si์นธ ๋งํผ ์ด๋ํ๋ค.
์ฌ๊ธฐ์ Si๊ฐ ๊ฒฉ์์ ํฌ๊ธฐ์ธ N๋ณด๋ค ํฌ๋ค๊ณ ์๊ฐํด๋ณด์. ๋ง์ฝ ํฌ๊ธฐ๊ฐ 6์ธ ๊ฒฉ์์์ x์ถ๋ฐฉํฅ์ผ๋ก 6๋งํผ ์ด๋ํ๋ฉด ์ ์๋ฆฌ๋ก ๋์์ค๊ฒ ๋๋ค. ์ ์๋ฆฌ๋ก ๋์์ค๋ ๋งํผ์ ์ด๋์ ๊ตณ์ด ๊ตฌํํด์ค ํ์๊ฐ ์๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ Si % N๋งํผ ์ด๋ํด์ฃผ๋ฉด ๋๋ค.
์ฌ๊ธฐ์ ํ์ด์ด๋ณผ์ ์ด๋์์ผฐ์ ๋ ํ์ด๋ ์ด์ด 1๋ณด๋ค ์์์ง๊ฑฐ๋ N๋ณด๋ค ์ปค์ง๋ ๊ฒฝ์ฐ๋ฅผ ์ ์๊ฐํด์ ํ์ด์ด๋ณผ๋ค์ ์ด๋์์ผ ์ค๋ค.
๊ทธ๋ฆฌ๊ณ ์ด๋ ํ์ ์์น๋ฅผ ( r , c ) ๋ผ๊ณ ํ๋ค๋ฉด Map[r][c] ์ ์ด๋์ํจ ํ์ด์ด๋ณผ์ ์ธ๋ฑ์ค๋ฅผ ๋ฃ์ด์ค๋ค.
2. ์ด๋์ด ๋ชจ๋ ๋๋ ๋ค, 2๊ฐ ์ด์์ ํ์ด์ด๋ณผ์ด ์๋ ์นธ์์๋ ๋ถํ ์ด ์ผ์ด๋๋ค.
๋ถํ ํ โ . ํ์ด์ด๋ณผ๋ค์ ๋ํ ์ ๋ณด๊ฐ ๋ณ๊ฒฝ๋ ๊ฒ์ด๋ค. ๊ธฐ์กด์ ํ์ด์ด๋ณผ์ ์์ด์ง๊ณ ์๋ก์ด ํ์ด์ด๋ณผ๋ง ๋จ์์์ด์ผํ๋ค.๊ทธ๋์ ๋๋ temp๋ผ๋ ๋ฒกํฐ์ ๋ถํ ํ์ ์์ด์ผ ํ๋ ํ์ด์ด๋ณผ๋ค์ ์ ๋ณด๋ฅผ ์ ์ฅํด๋์๋ค.
Map๋ฐฐ์ด์ ์ธ๋ฑ์ค๋ฅผ ๋๋ฉด์ ํด๋น ์นธ์ ๋ฒกํฐ ํฌ๊ธฐ๊ฐ 0์ด๋ฉด ์ฆ ํ์ด์ด๋ณผ์ด 0๊ฐ ์์ผ๋ฉด ์คํต.
ํด๋น ์นธ ๋ฒกํฐ ํฌ๊ธฐ๊ฐ 1์ด๋ฉด ํ์ด์ด๋ณผ์ด 1๊ฐ ์๋ค๋ ๋ป์ด๋ฏ๋ก ๋ถํ ํ ํ์ X. ๊ทธ๋ฆฌ๊ณ ๋ถํ ํ์๋ ๊ทธ๋๋ก ๋จ์์์ด์ผํจ
=> temp ๋ฐฐ์ด์ ํด๋น ํ์ด์ด๋ณผ ์ ๋ณด ์ ์ฅ
ํด๋น ์นธ์ ๋ฒกํฐ ํฌ๊ธฐ๊ฐ 2์ด์์ด๋ฉด ํ์ด์ด๋ณผ๋ค์ ํฉ์น ํ ๋ถํ ์์ผ์ผํ๋ค.
์๋ก ๋ง๋ค์ด์ง 4๊ฐ์ ํ์ด์ด๋ณผ๋ค์ ๋ํ ์ ๋ณด๋ง temp์ ์ ์ฅํด์ค๋ค.
=> ๊ธฐ์กด์ ํ์ด์ด๋ณผ์ ์ฌ๋ผ์ง๊ธฐ ๋๋ฌธ.
์ด๋ ๊ฒ ํด์ ๋ง์ง๋ง์ Fireball = temp ๋ฅผ ํตํด ํ์ด์ด๋ณผ๋ค์ ๋ํ ์ ๋ณด๋ฅผ ๋ณ๊ฒฝ์ํจ๋ค.
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#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 <deque>
#include <algorithm>
#include <iomanip>
#include <map>
#define mod 998244353
using namespace std;
typedef long long ll;
typedef priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Priority_queue;
const int INF = INT_MAX;
const int MAX_N = 50 + 5;
int N, M, K;
int dx[] = { 0,1,1,1,0,-1,-1,-1 };
int dy[] = { -1,-1,0,1,1,1,0,-1 };
vector<pair<pair<int, int>, pair<int, pair<int, int>>>> Fireball;
vector<pair<pair<int, int>, pair<int, pair<int, int>>>> temp;
vector<int> Map[MAX_N][MAX_N];
void move_and_seperate();
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M >> K;
for (int i = 0; i < M; i++) {
int r, c, m, d, s;
cin >> r >> c >> m >> s >> d;
Fireball.push_back({ {r,c},{m,{d,s}} });
}
while (K--) {
move_and_seperate();
}
int ans = 0;
for (int i = 0; i < Fireball.size(); i++) {
ans += Fireball[i].second.first;
}
cout << ans << "\n";
return 0;
}
void move_and_seperate() {
//Move
for (int i = 0; i < Fireball.size(); i++) {
pair<int, int> now = Fireball[i].first;
int mass = Fireball[i].second.first;
int direct = Fireball[i].second.second.first;
int speed = Fireball[i].second.second.second;
int move = speed % N;
pair<int, int> next = { now.first + dy[direct] * move, now.second + dx[direct] * move };
if (next.first < 1) {
next.first %= N;
next.first += N;
}
else if (next.first > N)
next.first %= N;
if (next.second < 1) {
next.second %= N;
next.second += N;
}
else if (next.second > N)
next.second %= N;
Fireball[i].first = next;
Map[next.first][next.second].push_back(i);
}
//Seperate
temp.clear();
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (Map[i][j].empty())
continue;
else if (Map[i][j].size() == 1) {
temp.push_back(Fireball[Map[i][j][0]]);
Map[i][j].clear();
continue;
}
int Mass_total = 0;
int Speed_total = 0;
int odd = 0;
for (int k = 0; k < Map[i][j].size(); k++) {
Mass_total += Fireball[Map[i][j][k]].second.first;
Speed_total += Fireball[Map[i][j][k]].second.second.second;
if (Fireball[Map[i][j][k]].second.second.first % 2)
odd++;
}
Mass_total = (int)floor((double)Mass_total / 5);
if (Mass_total == 0) {
Map[i][j].clear();
continue;
}
Speed_total = (int)floor((double)Speed_total / Map[i][j].size());
int Direction[] = { 0,2,4,6 };
if (odd != 0 && odd != Map[i][j].size())
for (int i = 0; i < 4; i++)
Direction[i] ++;
for (int k = 0; k < 4; k++)
temp.push_back({ {i,j},{Mass_total,{Direction[k], Speed_total}} });
Map[i][j].clear();
}
}
Fireball = temp;
}
|
cs |
ํ๊ณ ๋๋๊น ์ฌ์ค ๋ณ๊ฑฐ ์๋๊ฑฐ๊ฐ์๋ฐ, ๋ด ๊ธฐ์ค์ผ๋ก ๊ตฌํ์ด ์กฐ๊ธ ๊น๋ค๋กญ๊ณ ์ค๋๊ฑธ๋ ธ๋ค.
'๋ฐฑ์ค > Gold' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] 20058 : ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด์คํฐ (0) | 2022.05.31 |
---|---|
[BOJ] 20057 : ๋ง๋ฒ์ฌ ์์ด์ ํ ๋ค์ด๋ (0) | 2022.05.30 |
[BOJ] 20055 : ์ปจ๋ฒ ์ด์ด ๋ฒจํธ ์์ ๋ก๋ด (0) | 2022.05.23 |
[BOJ] 19238 : ์คํํธ ํ์ (0) | 2022.05.23 |
[BOJ] 17825 : ์ฃผ์ฌ์ ์ท๋์ด (0) | 2022.05.19 |