QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726646 | #5680. You You See What? | Nika# | WA | 1ms | 3608kb | C++17 | 2.2kb | 2024-11-09 04:50:22 | 2024-11-09 04:50:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s; cin >> s;
map<string, int> conv;
int uid = 0;
vector<int> nodes;
vector<int> next_node;
vector<string> node_strings;
auto lower = [] (string s){
string res;
for (char c: s) res += tolower(c);
return res;
};
auto handle = [&] (string s){
string lw = lower(s);
if (conv.find(lw) == conv.end()) conv[lw] = uid++;
int val = conv[lw];
next_node.push_back(val);
nodes.push_back(val);
node_strings.push_back(s);
};
string cur;
for (char c : s){
if (c == '!') {
handle(cur);
cur = "";
}
else cur += c;
}
if (cur != "") handle(cur);
next_node.push_back(-1);
reverse(begin(next_node), end(next_node));
next_node.pop_back();
reverse(begin(next_node), end(next_node));
// for (auto S: node_strings) cout << S << " ";
// cout << endl;
// for (auto S: nodes) cout << S << " ";
// cout << endl;
// for (auto S: next_node) cout << S << " ";
// cout << endl;
vector<int> ord;
set<pair<int, int>> edges;
int n = int(size(nodes));
for (int i = 0; i < n; i++){
// for (auto S: ord) cout << S << " ("+node_strings[S] << ") ";
// cout << endl;
pair<int, int> rev_edge = make_pair(next_node[i], nodes[i]);
if (edges.count(rev_edge)){
while (size(ord) > 0 && nodes[ord.back()] != next_node[i]){
int idx = ord.back();
edges.erase(make_pair(nodes[idx], next_node[idx]));
ord.pop_back();
}
if (size(ord) > 0){
int idx = ord.back();
edges.erase(make_pair(nodes[idx], next_node[idx]));
ord.pop_back();
}
continue;
}
// for (auto S: ord) cout << S << " ("+node_strings[S] << ") ";
// cout << endl;
ord.push_back(i);
edges.insert(make_pair(nodes[i], next_node[i]));
// for (auto S: ord) cout << S << " ("+node_strings[S] << ") ";
// cout << endl;
// cout << endl;
}
string res;
for (int i : ord) res += node_strings[i]+"!";
res.pop_back();
cout << res << endl;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher
output:
texasam!rice!dev!bresearch!bpoucher
result:
ok single line: 'texasam!rice!dev!bresearch!bpoucher'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
texasam!Rice!baYlor!csdept!BayloR!dev!Rice!bresearch!bpoucher
output:
texasam!Rice!BayloR!dev!Rice!bresearch!bpoucher
result:
wrong answer 1st lines differ - expected: 'texasam!Rice!baYlor!dev!Rice!bresearch!bpoucher', found: 'texasam!Rice!BayloR!dev!Rice!bresearch!bpoucher'