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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
| // 더 많은 정보는 42jerrykim.github.io 에서 확인하세요.
#include <bits/stdc++.h>
using namespace std;
enum Suit { SPADES=0, DIAMONDS=1, HEARTS=2, CLUBS=3, NOSUIT=4 };
enum Color { BLACK=0, RED=1 };
struct Card {
bool isJoker = false;
bool isBlackJoker = false; // true for JB, false for JC
Suit suit = NOSUIT;
int rank = 0; // 2..10, 11=J, 12=Q, 13=K, 1=A
string code;
bool operator==(const Card& o) const {
if (isJoker != o.isJoker) return false;
if (isJoker) return isBlackJoker == o.isBlackJoker;
return suit == o.suit && rank == o.rank;
}
bool operator<(const Card& o) const {
if (isJoker != o.isJoker) return isJoker < o.isJoker;
if (isJoker) return isBlackJoker < o.isBlackJoker;
if (suit != o.suit) return suit < o.suit;
return rank < o.rank;
}
};
static inline Color suitColor(Suit s) {
return (s == SPADES || s == CLUBS) ? BLACK : RED;
}
static inline string makeCode(Suit s, int r) {
string res;
res.push_back(s == SPADES ? 'S' : s == DIAMONDS ? 'D' : s == HEARTS ? 'H' : 'C');
if (r == 1) res += "A";
else if (r == 11) res += "J";
else if (r == 12) res += "Q";
else if (r == 13) res += "K";
else res += to_string(r);
return res;
}
static inline Card makeCard(Suit s, int r) {
Card c; c.isJoker=false; c.suit=s; c.rank=r; c.code=makeCode(s,r); return c;
}
static inline Card blackJoker() { Card c; c.isJoker=true; c.isBlackJoker=true; c.code="JB"; return c; }
static inline Card colorJoker() { Card c; c.isJoker=true; c.isBlackJoker=false; c.code="JC"; return c; }
static inline bool isPointCard(const Card& c) {
if (c.isJoker) return false;
return (c.rank == 10 || c.rank == 11 || c.rank == 12 || c.rank == 13 || c.rank == 1);
}
static inline bool parseNormalCard(const string& t, Card& out) {
out.code = t;
if (t == "JB") { out.isJoker = true; out.isBlackJoker = true; return true; }
if (t == "JC") { out.isJoker = true; out.isBlackJoker = false; return true; }
if (t.size() < 2) return false;
Suit suit = NOSUIT;
if (t[0]=='S') suit=SPADES;
else if (t[0]=='D') suit=DIAMONDS;
else if (t[0]=='H') suit=HEARTS;
else if (t[0]=='C') suit=CLUBS;
else return false;
string rstr = t.substr(1);
int rank = 0;
if (rstr == "A") rank = 1;
else if (rstr == "J") rank = 11;
else if (rstr == "Q") rank = 12;
else if (rstr == "K") rank = 13;
else {
for (char c: rstr) if (!isdigit((unsigned char)c)) return false;
rank = stoi(rstr);
if (rank < 2 || rank > 10) return false;
}
out.isJoker=false; out.suit=suit; out.rank=rank;
return true;
}
struct Bid {
bool valid = false;
bool noGiruda = false;
Suit suit = NOSUIT;
int target = 0;
};
static inline bool parseBid(const string& t, Bid& b) {
if (t == "N") { b.valid=false; return true; }
if (t.size() < 2) return false;
if (t[0] == 'X') {
string n = t.substr(1);
for (char c: n) if (!isdigit((unsigned char)c)) return false;
b.noGiruda = true; b.suit=NOSUIT; b.target=stoi(n); b.valid=true;
if (b.target < 12 || b.target > 20) return false;
return true;
}
Suit s = NOSUIT;
if (t[0]=='S') s=SPADES;
else if (t[0]=='D') s=DIAMONDS;
else if (t[0]=='H') s=HEARTS;
else if (t[0]=='C') s=CLUBS;
else return false;
string n = t.substr(1);
for (char c: n) if (!isdigit((unsigned char)c)) return false;
int tg = stoi(n);
if (tg < 13 || tg > 20) return false;
b.valid=true; b.noGiruda=false; b.suit=s; b.target=tg;
return true;
}
static inline double dealMistakeWeight(const vector<Card>& hand10) {
double w = 0.0;
for (auto &c: hand10) {
if (c.isJoker) w += -0.5;
else if (c.suit == SPADES && c.rank == 1) w += -1.0;
else if (isPointCard(c)) w += 1.0;
}
return w;
}
static inline bool isMighty(const Card& c, bool noGiruda, Suit giruda) {
if (c.isJoker) return false;
if (!noGiruda && giruda == SPADES) return (c.suit == DIAMONDS && c.rank == 1);
return (c.suit == SPADES && c.rank == 1);
}
static inline bool isTrump(const Card& c, bool noGiruda, Suit giruda) {
return (!noGiruda && !c.isJoker && c.suit == giruda);
}
static inline int suitStrengthOrder(Suit s) {
if (s == SPADES) return 4;
if (s == DIAMONDS) return 3;
if (s == HEARTS) return 2;
if (s == CLUBS) return 1;
return 0;
}
static inline pair<int,int> intraRankKey(const Card& c) {
int ro = (c.rank == 1 ? 14 : c.rank);
return {ro, suitStrengthOrder(c.suit)};
}
struct StartInfo {
bool isJokerStart = false;
vector<Suit> allowed; // for Joker-start: 1 or 2 suits; for normal start: [suit]
bool isBlack = false; // only for Joker-start
bool invalid = false;
Card firstCard;
};
static inline StartInfo parseStartToken(const string& token) {
StartInfo si;
if (token == "JD") { si.isJokerStart=true; si.allowed={DIAMONDS}; si.isBlack=false; return si; }
if (token == "JH") { si.isJokerStart=true; si.allowed={HEARTS}; si.isBlack=false; return si; }
if (token == "JDH") { si.isJokerStart=true; si.allowed={DIAMONDS,HEARTS}; si.isBlack=false; return si; }
if (token == "JS") { si.isJokerStart=true; si.allowed={SPADES}; si.isBlack=true; return si; }
if (token == "JC") { si.isJokerStart=true; si.allowed={CLUBS}; si.isBlack=true; return si; }
if (token == "JSC") { si.isJokerStart=true; si.allowed={SPADES,CLUBS}; si.isBlack=true; return si; }
Card c;
if (!parseNormalCard(token, c)) { si.invalid=true; return si; }
if (c.isJoker) { si.invalid=true; return si; }
si.isJokerStart=false; si.firstCard=c; si.allowed={c.suit};
return si;
}
struct RankContext {
bool noGiruda = false;
Suit giruda = NOSUIT;
int roundIndex = 0; // 0..9
vector<Suit> allowed; // 1 or 2 suits
bool firstIsJoker = false;
bool firstColorIsBlack = false; // for no-giruda joker color comparison
bool forcedJokerActive = false; // Joker-gun active this round?
bool forcedJokerIsBlack = false; // which joker is forced if active
};
static inline int strengthClass(const Card& c, const RankContext& rc) {
bool jokerPowerless = false;
if (c.isJoker) {
if (rc.roundIndex == 0 || rc.roundIndex == 9) jokerPowerless = true;
if (rc.forcedJokerActive && (c.isBlackJoker == rc.forcedJokerIsBlack)) jokerPowerless = true;
}
if (isMighty(c, rc.noGiruda, rc.giruda)) return 0;
if (!rc.noGiruda) {
if (c.isJoker) {
if (!jokerPowerless) {
bool girudaBlack = (suitColor(rc.giruda) == BLACK);
bool same = (c.isBlackJoker == girudaBlack);
return same ? 1 : 3;
} else {
return 6; // powerless joker (weakest)
}
}
if (isTrump(c, rc.noGiruda, rc.giruda)) return 2;
bool isAllowed = false;
for (auto s: rc.allowed) if (!c.isJoker && c.suit == s) { isAllowed = true; break; }
if (isAllowed) return 4;
return 5;
} else {
if (c.isJoker) {
if (!jokerPowerless) {
bool same = (c.isBlackJoker == rc.firstColorIsBlack);
return same ? 1 : 3;
} else {
return 5; // powerless joker (weakest in no-giruda)
}
}
bool isAllowed = false;
for (auto s: rc.allowed) if (!c.isJoker && c.suit == s) { isAllowed = true; break; }
if (isAllowed) return 2;
return 4;
}
}
static int decideWinner(const array<Card,5>& played,
const RankContext& baseRc) {
int bestIdx = 0;
int bestClass = INT_MAX;
pair<int,int> bestIntra = {-1,-1};
for (int i=0;i<5;i++) {
int cls = strengthClass(played[i], baseRc);
pair<int,int> intra = {-100,-100};
if (cls == 0) intra = {200, 200}; // Mighty
else if (!played[i].isJoker && (cls!=6)) intra = intraRankKey(played[i]);
if (cls < bestClass || (cls == bestClass && intra > bestIntra)) {
bestClass = cls; bestIntra = intra; bestIdx = i;
}
}
return bestIdx;
}
struct JokerGunState {
bool active = false;
bool forceBlack = false; // true → JB forced; false → JC forced
int shooterPlayer = -1;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<vector<string>> initialTokens(5, vector<string>(10));
for (int i=0;i<5;i++) for (int j=0;j<10;j++) if (!(cin >> initialTokens[i][j])) return 0;
vector<string> bidTok(5); for (int i=0;i<5;i++) cin >> bidTok[i];
vector<string> discardTok(4); for (int i=0;i<4;i++) cin >> discardTok[i];
string friendTok; cin >> friendTok;
vector<array<string,5>> roundsTok(10);
for (int r=0;r<10;r++) for (int i=0;i<5;i++) cin >> roundsTok[r][i];
vector<Card> deck;
for (int s=0;s<4;s++) {
for (int r=2;r<=10;r++) deck.push_back(makeCard((Suit)s, r));
deck.push_back(makeCard((Suit)s,11));
deck.push_back(makeCard((Suit)s,12));
deck.push_back(makeCard((Suit)s,13));
deck.push_back(makeCard((Suit)s,1));
}
deck.push_back(blackJoker());
deck.push_back(colorJoker());
set<string> allDeckCodes; for (auto &c: deck) allDeckCodes.insert(c.code);
auto parseCardVec = [&](const vector<string>& v) {
vector<Card> res; res.reserve(v.size());
for (auto &t: v) {
Card c;
if (!parseNormalCard(t, c)) { c.code = t + "#INVALID"; }
res.push_back(c);
}
return res;
};
vector<vector<Card>> initHands(5);
for (int i=0;i<5;i++) initHands[i] = parseCardVec(initialTokens[i]);
bool distViolation = false;
set<string> seen;
for (int i=0;i<5;i++) for (auto &c: initHands[i]) {
if (!allDeckCodes.count(c.code)) distViolation = true;
if (!seen.insert(c.code).second) distViolation = true;
}
if (distViolation) { cout << "Rule Violation\n"; return 0; }
bool hasDealMistake = false;
for (int i=0;i<5;i++) if (dealMistakeWeight(initHands[i]) <= 1.0) hasDealMistake = true;
if (hasDealMistake) { cout << "Deal Mistake\n"; return 0; }
set<string> remaining = allDeckCodes;
for (auto &s: seen) remaining.erase(s);
if ((int)remaining.size() != 4) { cout << "Rule Violation\n"; return 0; }
vector<Card> remain4; for (auto &c: deck) if (remaining.count(c.code)) remain4.push_back(c);
vector<Bid> bids(5);
for (int i=0;i<5;i++) if (!parseBid(bidTok[i], bids[i])) { cout << "Rule Violation\n"; return 0; }
int pres = -1, bestEff = -1, tiePref = -1, bestRawTarget = -1; Suit bestSuit = NOSUIT;
for (int i=0;i<5;i++) if (bids[i].valid) {
int eff = bids[i].noGiruda ? (bids[i].target + 1) : bids[i].target;
int pref = bids[i].noGiruda ? 2 : 1;
if (eff > bestEff) { bestEff = eff; tiePref=pref; pres=i; bestSuit=bids[i].noGiruda?NOSUIT:bids[i].suit; bestRawTarget=bids[i].target; }
else if (eff == bestEff) {
if (pref > tiePref) { tiePref=pref; pres=i; bestSuit=bids[i].noGiruda?NOSUIT:bids[i].suit; bestRawTarget=bids[i].target; }
else if (pref == tiePref) {
if (!bids[i].noGiruda && bestSuit!=NOSUIT) {
int a = suitStrengthOrder(bids[i].suit), b = suitStrengthOrder(bestSuit);
if (a > b || (a==b && i<pres)) { pres=i; bestSuit=bids[i].suit; bestRawTarget=bids[i].target; }
} else { if (i < pres) { pres=i; bestSuit=NOSUIT; bestRawTarget=bids[i].target; } }
}
}
}
if (pres == -1) { cout << "Rule Violation\n"; return 0; }
bool noGiruda = bids[pres].noGiruda; Suit giruda = noGiruda ? NOSUIT : bids[pres].suit; int pledge = bids[pres].target;
vector<multiset<string>> hands(5);
for (int i=0;i<5;i++) for (auto &c: initHands[i]) hands[i].insert(c.code);
for (auto &c: remain4) hands[pres].insert(c.code);
vector<Card> discards = parseCardVec(discardTok);
for (auto &c: discards) {
if (!allDeckCodes.count(c.code) || !hands[pres].count(c.code)) { cout << "Rule Violation\n"; return 0; }
hands[pres].erase(hands[pres].find(c.code));
}
Card friendCard; if (!parseNormalCard(friendTok, friendCard)) { cout << "Rule Violation\n"; return 0; }
int friendPlayer = -1; for (int p=0;p<5;p++) if (hands[p].count(friendCard.code)) { friendPlayer=p; break; }
bool friendInDiscards = false; for (auto &c: discards) if (c.code == friendCard.code) { friendInDiscards = true; break; }
bool friendless = (friendPlayer == pres) || friendInDiscards;
auto isGovernment = [&](int p){ return (p == pres) || (!friendless && p == friendPlayer); };
int govScore = 0, oppScore = 0; for (auto &c: discards) if (isPointCard(c)) govScore++;
auto jokerGunsForGiruda = [&](bool noG, Suit g)->vector<Card>{
vector<Card> v;
if (!noG && g == HEARTS) { v.push_back(makeCard(DIAMONDS,3)); v.push_back(makeCard(CLUBS,3)); }
else if (!noG && g == CLUBS) { v.push_back(makeCard(HEARTS,3)); v.push_back(makeCard(SPADES,3)); }
else { v.push_back(makeCard(HEARTS,3)); v.push_back(makeCard(CLUBS,3)); }
return v;
};
vector<Card> guns = jokerGunsForGiruda(noGiruda, giruda);
auto isJokerGunCard = [&](const Card& c){ for (auto &g: guns) if (c == g) return true; return false; };
auto getCardFromToken = [&](const string& t, bool isStartToken, StartInfo &si)->Card {
if (isStartToken) {
si = parseStartToken(t);
if (!si.isJokerStart && si.invalid) { Card x; x.code="#INVALID"; return x; }
if (!si.isJokerStart) return si.firstCard;
return si.isBlack ? blackJoker() : colorJoker();
} else {
StartInfo tmp; Card c; if (!parseNormalCard(t, c)) { c.code="#INVALID"; } return c;
}
};
auto countTrumpInHand = [&](int p)->int{
if (noGiruda) return 0;
int cnt = 0;
for (int r=1;r<=13;r++) {
if (r==1 || (2<=r && r<=10) || r==11 || r==12 || r==13) {
string cd = makeCode(giruda, r);
cnt += (int)hands[p].count(cd);
}
}
return cnt;
};
auto hasMightyInHand = [&](int p)->bool{
Card m = (!noGiruda && giruda==SPADES) ? makeCard(DIAMONDS,1) : makeCard(SPADES,1);
return hands[p].count(m.code) > 0;
};
int starter = pres; bool laterRuleViolation = false;
for (int rnd=0; rnd<10; rnd++) {
array<string,5> tokens = roundsTok[rnd];
array<int,5> orderToPlayer{}; array<Card,5> played{}; array<StartInfo,5> startInfo{};
for (int k=0;k<5;k++) {
int p = (starter + k) % 5; orderToPlayer[k] = p; bool isStart = (k==0); StartInfo si; Card c = getCardFromToken(tokens[p], isStart, si);
if (c.code == "#INVALID") { laterRuleViolation = true; }
played[k] = c; startInfo[k] = si;
}
if (laterRuleViolation) break;
vector<Suit> allowed; bool firstIsJokerStart = startInfo[0].isJokerStart; bool firstColorIsBlack = false;
if (firstIsJokerStart) { allowed = startInfo[0].allowed; firstColorIsBlack = startInfo[0].isBlack; }
else { if (played[0].isJoker) { laterRuleViolation = true; break; } allowed = { played[0].suit }; firstColorIsBlack = (suitColor(played[0].suit) == BLACK); }
if (!noGiruda && rnd == 0 && starter == pres) {
int trumpCnt = countTrumpInHand(pres); bool mightyIn = hasMightyInHand(pres);
bool allTrump = (trumpCnt == 10); bool nineTrumpPlusMighty = (trumpCnt == 9 && mightyIn);
Card led = played[0]; bool ledIsTrump = (!led.isJoker && led.suit == giruda); bool ledIsMighty = isMighty(led, noGiruda, giruda);
if (nineTrumpPlusMighty && !ledIsMighty) { laterRuleViolation = true; break; }
if (!allTrump && ledIsTrump) { laterRuleViolation = true; break; }
}
JokerGunState jg; if (!firstIsJokerStart && isJokerGunCard(played[0])) {
jg.active = true; bool gunIsBlack = (suitColor(played[0].suit) == BLACK); jg.forceBlack = gunIsBlack; jg.shooterPlayer = orderToPlayer[0];
Card forced = jg.forceBlack ? blackJoker() : colorJoker();
if (hands[jg.shooterPlayer].count(forced.code)) { jg.active = false; }
else { bool someoneHas=false; for (int p=0;p<5;p++) if (hands[p].count(forced.code)) { someoneHas=true; break; } if (!someoneHas) jg.active = false; }
}
auto mustFollowSuit = [&](int p)->bool{
for (auto s: allowed) {
for (int r=1;r<=13;r++) {
if (r==1 || (2<=r && r<=10) || r==11 || r==12 || r==13) {
string cc = makeCode(s, r);
if (hands[p].count(cc)) return true;
}
}
}
return false;
};
Card forcedJoker = jg.active ? (jg.forceBlack ? blackJoker() : colorJoker()) : Card{};
for (int k=0;k<5;k++) {
int p = orderToPlayer[k]; Card c = played[k];
if (!hands[p].count(c.code)) { laterRuleViolation = true; break; }
if (jg.active && hands[p].count(forcedJoker.code)) {
if (!(c.isJoker && c.isBlackJoker == forcedJoker.isBlackJoker)) {
if (!isMighty(c, noGiruda, giruda)) { laterRuleViolation = true; break; }
}
}
if (mustFollowSuit(p)) {
if (!c.isJoker && !isMighty(c, noGiruda, giruda)) {
bool ok=false; for (auto s: allowed) if (c.suit == s) { ok=true; break; }
if (!ok) { laterRuleViolation = true; break; }
}
}
hands[p].erase(hands[p].find(c.code));
}
if (laterRuleViolation) break;
RankContext rc; rc.noGiruda = noGiruda; rc.giruda = giruda; rc.roundIndex = rnd; rc.allowed = allowed; rc.firstIsJoker = firstIsJokerStart; rc.firstColorIsBlack = firstColorIsBlack; rc.forcedJokerActive = jg.active; rc.forcedJokerIsBlack = jg.forceBlack;
int winnerIdx = decideWinner(played, rc); int winnerPlayer = orderToPlayer[winnerIdx];
int pts = 0; for (int k=0;k<5;k++) if (isPointCard(played[k])) pts++;
if (isGovernment(winnerPlayer)) govScore += pts; else oppScore += pts;
starter = winnerPlayer;
}
if (laterRuleViolation) { cout << "Rule Violation\n"; return 0; }
int diff = govScore - pledge; if (govScore >= pledge) cout << diff << " Government Party\n"; else cout << diff << " Opposition Party\n"; return 0;
}
|