QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726631#5680. You You See What?Nika#WA 1ms3612kbC++172.4kb2024-11-09 04:13:452024-11-09 04:13:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 04:13:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3612kb
  • [2024-11-09 04:13:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void solve() {
  string s; cin >> s;
  map<string, int> conv;

  int uid = 0;

  vector<int> a, nxt;
  vector<string> parts;

  auto lower = [] (string s){
    string res;
    for (char c: s) res += tolower(c);
    return res;
  };

  string base;
  for (char c: s){
    if (c == '!') {
      string B = lower(base);
      if (conv.find(B) == conv.end()){
        conv[B] = uid++;
      }

      if (size(a) > 0) nxt.push_back(conv[B]);
      a.push_back(conv[B]);
      parts.push_back(base);
      base = "";
    }
    else {
      base += c;
    }
  }

  if (base != "") {
    string B = lower(base);
    if (conv.find(B) == conv.end()){
        conv[B] = uid++;
    }

    if (size(a) > 0) nxt.push_back(conv[B]);
    a.push_back(conv[B]);
    parts.push_back(base);
  }

  nxt.push_back(int(1e9));

  // for (string s : parts) cout << s << " ";
  // cout << endl;

  // for (int i : a) cout << i << " ";
  // cout << endl;

  // for (int i : nxt) cout << i << " ";
  // cout << endl;

  // cout << endl;
  
  vector<int> left;
  set<pair<int, int>> cur;

  int n = int(size(a));
  for (int i = 0; i < n; i++){

    // cout << "LEFT: ";
    // for (auto p : left) cout << p << " ";
    // cout << endl;

    // cout << "CUR: ";
    // for (auto p: cur) cout << p.first << ", " << p.second << " ";
    // cout << endl;

    // cout << endl;
    // cout << i << " " << a[i] << endl;

    if (i < n-1){
      pair<int, int> RE = make_pair(nxt[i], a[i]);
      // cout << RE.first << " " << RE.second << endl;
      if (cur.count(RE)) {
        while (a[left.back()] != RE.first){
          int L = left.back();
          // cout << "REM " << L << " " << a[L] << " " << nxt[L] << endl;
          cur.erase(make_pair(nxt[L], a[L]));
          left.pop_back();
        }
        continue;
      }
    }

    // cout << "INS " << i << " " << a[i] << " " << nxt[i] << endl;
    cur.insert(make_pair(a[i], nxt[i]));
    left.push_back(i);
  }

  // for (int i : left) cout << i << " ";
  // cout << endl;
  
  int idx = 0;
  string res;
  while (idx < size(left)){
    while (idx+1 < size(left) && a[left[idx]] == a[left[idx+1]]) idx++;
    res += parts[left[idx++]]+"!";
  }

  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: 3564kb

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: 0ms
memory: 3612kb

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'