0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 07:08:46 +00:00
OI-codes/LibreOJ/6122/data/spj.cpp

102 lines
3.0 KiB (Stored with Git LFS)
C++

// Fuck t*h's cache'
#include "testlib.h"
#include <cstdlib>
#include <map>
#include <string>
#include <tuple>
const char *NO_SOL = "No Solution!";
const int MAXN = 103;
int n, v;
std::string city[MAXN];
std::map<std::string, int> id;
bool g[MAXN][MAXN] = {{ false }};
int route[MAXN];
bool vis[MAXN];
typedef std::tuple<int, TResult, std::string> answer_t;
answer_t read_answer(InStream &ouf)
{
std::string m_str = ouf.readLine();
int m = -1;
if (m_str == NO_SOL) return answer_t(-1, _ok, "" );
m = strtol(m_str.c_str(), NULL, 10) + 1;
for (int i = 0; i < m; ++i) {
std::string s = ouf.readToken();
std::map<std::string, int>::iterator p = id.find(s);
if (p == id.end()) {
return answer_t(m, _wa, "Nonexistent city name " + s);
}
route[i] = p->second;
}
for (int i = 0; i < n; ++i) vis[i] = false;
int phase = 0;
for (int i = 0; i < m; ++i) {
if (vis[route[i]]) {
return answer_t(m, _wa, "Non-westernmost city " + city[route[i]] + " should not be visited more than once");
}
vis[route[i]] = true;
if (i == 0) {
if (route[i] != 0) {
return answer_t(m, _wa, "First city should be the westernmost one " + city[0]);
}
vis[route[i]] = false; // Will be visited twice
} else {
if (!g[route[i - 1]][route[i]]) {
return answer_t(m, _wa, "Nonexistent flight " + city[route[i - 1]] + "-" + city[route[i]]);
} else if ((phase == 0) ^ (route[i] > route[i - 1])) {
return answer_t(m, _wa, "Incorrect direction " + city[route[i - 1]] + "-" + city[route[i]]);
}
if (route[i] == n - 1) phase = 1;
}
}
if (phase == 0) {
return answer_t(m, _wa, "Didn't reach the easternmost city " + city[n - 1]);
}
if (route[m - 1] != 0) {
return answer_t(m, _wa, "Last city should be the westernmost one " + city[0]);
}
return answer_t(m, _ok, "");
}
int main(int argc, char *argv[])
{
registerTestlibCmd(argc, argv);
n = inf.readInt();
v = inf.readInt();
for (int i = 0; i < n; ++i) {
city[i] = inf.readToken();
id[city[i]] = i;
}
for (int i = 0; i < v; ++i) {
std::string s = inf.readToken();
std::string t = inf.readToken();
g[id[s]][id[t]] = g[id[t]][id[s]] = true;
}
auto jury_ans = read_answer(ans);
auto ptcp_ans = read_answer(ouf);
if (std::get<1>(jury_ans) != _ok) {
quitf(_fail, "Jury's answer is invalid: %s", std::get<2>(jury_ans).c_str());
}
if (std::get<1>(ptcp_ans) != _ok) {
quitf(std::get<1>(ptcp_ans), "Invalid: %s", std::get<2>(ptcp_ans).c_str());
}
if (std::get<0>(jury_ans) > std::get<0>(ptcp_ans)) {
quitf(_wa, "Participant's answer is suboptimal");
} else if (std::get<0>(jury_ans) < std::get<0>(ptcp_ans)) {
quitf(_fail, "Jury's answer is suboptimal! O O");
}
quitf(_ok, "*\\(^ ^)/*");
return 0;
}