티스토리 뷰

728x90

문제 링크

https://www.acmicpc.net/problem/16722


어렵진 않지만 귀찮은 구현문제이다.

주어진 9개 그림의 모든 조합을 미리 구해놓고 쿼리를 해결하자.



정답 코드

#include <iostream>
#include <tuple>
#include <algorithm>
#include <string>
using namespace std;
bool comb[10][10][10], chk[10][10][10];
bool foo(const string &x, const string &xx, const string &xxx) {
return (x == xx && xx == xxx) || (x != xx && xx != xxx && xxx != x);
}
void bar(int &a, int &b, int &c) {
int l = min({ a, b, c });
int r = max({ a, b, c });
b = a + b + c - l - r;
a = l;
c = r;
}
tuple<string, string, string> p[10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i = 1; i < 10; i++) {
string x, y, z;
cin >> x >> y >> z;
p[i] = { x, y, z };
}
int kk = 0;
for (int i = 1; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
for (int k = j + 1; k < 10; k++) {
auto[x, y, z] = p[i];
auto[xx, yy, zz] = p[j];
auto[xxx, yyy, zzz] = p[k];
if(comb[i][j][k] = foo(x, xx, xxx) && foo(y, yy, yyy) && foo(z, zz, zzz)) kk++;
}
}
}
int n;
cin >> n;
char c;
bool g = false;
int ans = 0;
while (n--) {
cin >> c;
if (c == 'H') {
int a, b, c;
cin >> a >> b >> c;
bar(a, b, c);
if (!chk[a][b][c] && comb[a][b][c]) {
chk[a][b][c] = true;
ans++;
kk--;
}
else {
ans--;
}
}
else {
if (!g && kk == 0) {
g = true;
ans += 3;
}
else {
ans--;
}
}
}
cout << ans;
}
view raw 16722.cpp hosted with ❤ by GitHub
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/04   »
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
글 보관함