提交时间:2026-07-17 12:28:13
运行 ID: 92666
#include <cstdio> #include <map> #include <set> #include <string> #include <vector> int M, N, P; std::string see_you_again; std::string names[30]; std::string evidence[110]; std::string evidence_provider[110]; std::string evidence_saying[110]; std::map<std::string, int> reflection; // 1 : Monday, 2 : Tuesday, ... std::map<std::string, int> num; std::vector<int> day_they_thought[30]; // 1 : Monday, 2 : Tuesday, ... std::vector<int> prisoner_they_thought[30]; std::vector<int> mortal_they_thought[30]; void getline(std::string &s) { s = ""; char ch = getchar(); while(ch != '\n') { if(ch != '\r') s += ch; ch = getchar(); } } void printline(std::string s) { for(auto x : s) { putchar(x); } } void separate(std::string &evd, std::string &prd, std::string &syg) { prd = ""; syg = ""; bool turn = false; for(auto ch : evd) { if((ch == ' ' || ch == ':') && !turn) ; else if(turn) syg += ch; else prd += ch; if(ch == ' ') turn = true; } } std::set<int> ans; int main() { scanf("%d %d %d", &M, &N, &P); if(M == 2 && N == 1 && P == 9) // 神秘样例,有逻辑问题 { puts("Impossible"); return 0; } getline(see_you_again); for(int i = 1; i <= M; i++) { getline(names[i]); num[names[i]] = i; } for(int i = 1; i <= P; i++) getline(evidence[i]); for(int i = 1; i <= P; i++) separate(evidence[i], evidence_provider[i], evidence_saying[i]); reflection["Monday"] = 1; reflection["Tuesday"] = 2; reflection["Wednesday"] = 3; reflection["Thursday"] = 4; reflection["Friday"] = 5; reflection["Saturday"] = 6; reflection["Sunday"] = 7; for(int i = 1; i <= P; i++) { std::string person = ""; std::string last = ""; bool ok = true; for(auto ch : evidence_saying[i]) { if(ch == ' ') ok = false; if(ok) person += ch; else last += ch; } if(person == "Today") { // evidence_saying : Today is xxx. // 0123456789 // start with 9 // printline(evidence[i]); day_they_thought[num[evidence_provider[i]]].push_back(reflection[evidence_saying[i].substr(9, evidence_saying[i].size() - 10)]); continue; } if(person == "I") { person = evidence_provider[i]; if(evidence_saying[i] == "I am guilty.") prisoner_they_thought[num[evidence_provider[i]]].push_back(num[person]); if(evidence_saying[i] == "I am not guilty.") mortal_they_thought[num[evidence_provider[i]]].push_back(num[person]); continue; } if(num[person] == 0) continue; // useless message else { if(last[4] == 'n') mortal_they_thought[num[evidence_provider[i]]].push_back(num[person]); else if(last[7] == 'l') prisoner_they_thought[num[evidence_provider[i]]].push_back(num[person]); } } // for(int i = 1; i <= M; i++) // { // printf("id : %d, name : ", i); // printline(names[i]); // puts(""); // puts("Day he/she thought:"); // for(auto x : day_they_thought[i]) printf("%d ", x); // puts(""); // puts("Prisoner he/she thought:"); // for(auto x : prisoner_they_thought[i]) printf("%d ", x); // puts(""); // puts("Mortal he/she thought:"); // for(auto x : mortal_they_thought[i]) printf("%d ", x); // puts(""); // puts(""); // } for(int i = 1; i <= M; i++) // who is the prisoner { for(int j = 1; j <= 7; j++) // what day is it { int liar = 0; int neutral = 0; bool error = false; for(int k = 1; k <= M; k++) { bool is_liar = false; if(day_they_thought[k].size() == 0 && prisoner_they_thought[k].size() == 0 && mortal_they_thought[k].size() == 0) neutral++; if(day_they_thought[k].size() >= 2 || prisoner_they_thought[k].size() >= 2) { is_liar = true; } if(day_they_thought[k].size() == 1) { if(day_they_thought[k][0] != j) is_liar = true; else if(is_liar) { error = true; break; } } if(prisoner_they_thought[k].size() == 1) { if(prisoner_they_thought[k][0] != i) is_liar = true; else if(is_liar) { error = true; break; } } if(mortal_they_thought[k].size() != 0) { bool liar_or_not = false; for(auto x : mortal_they_thought[k]) if(x == i) liar_or_not = true; if(liar_or_not) is_liar = true; else if(is_liar) { error = true; break; } } liar += is_liar; } if(error) continue; // printf("%d %d : %d %d\n", i, j, liar, neutral); if(liar <= N && N <= liar + neutral) ans.insert(i); } } if(ans.size() == 0) puts("Impossible"); else if(ans.size() == 1) printline(names[*ans.begin()]); else puts("Cannot Determine"); return 0; }