QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606145#7738. Equivalent RewritingyangrunWA 0ms28744kbC++141.9kb2024-10-02 22:25:422024-10-02 22:25:42

Judging History

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

  • [2024-10-02 22:25:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:28744kb
  • [2024-10-02 22:25:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read() {
  int res = 0, flg = 1;
  char c = getchar();
  while(!isdigit(c)) {
    if(c == '-') flg = 0;
    c = getchar();
  }
  while(isdigit(c)) {
    res = (res << 3) + (res << 1) + (c ^ 48);
    c = getchar();
  }
  return flg ? res : -res;
}
const int N = 1e6 + 10;
vector<int> v[N];
int n, m, has[N];
int inter(vector<int>& a, vector<int>& b) {
  int i = 0, j = 0;
  int res = 0;
  while(i < a.size() && j < b.size()) {
    if(a[i] < b[j]) i++;
    else if(a[i] > b[j]) j++;
    else {
      i++, j++;
      res++;
    }
  }
  return res;
}
void solve() {
  n = read(), m = read();
  for(int i = 1; i <= m; i++) has[i] = 0;
  int num;
  for(int i = 1; i <= n; i++) {
    v[i].clear();
    num = read();
    for(int j = 1; j <= num; j++) {
      v[i].push_back(read());
    }
    sort(v[i].begin(), v[i].end());
  }
  for(int i = 0; i < v[n].size(); ++i) {
    has[v[n][i]] = 1;
  }
  for(int i = n - 1; i; --i) {
    num = inter(v[i], v[i + 1]);
    if(!num) {
      cout << "Yes\n";
      for(int j = 1; j < i; j++) cout << j << ' ';
      cout << i + 1 << ' ';
      cout << i << ' ';
      for(int j = i + 2; j <= n; j++) cout << j << ' ';
      cout << '\n';
      return;
    }
    int r = v[i].size() - 1;
    for(int j = 0; j <= r; j++) {
      if(has[v[i][j]]) {
        swap(v[i][j], v[i][r]);
        r--;
        j--;
      }
    }
    for(int j = 0; j < v[i].size(); j++) {
      cout << v[i][j] << ' ';
    }
    
    v[i].erase(v[i].begin() + r + 1, v[i].end());
    
    for(int j = 0; j < v[i].size(); j++) {
      has[v[i][j]] = 1;
    }
    for(int j = 0; j < v[i].size(); j++) {
      has[v[i][j]] = 1;
    }
  }
  cout << "No" << '\n';
}
signed main() {
  int t = read();
  while(t--) {
    solve();
  }
  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 28744kb

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
1 3 2 
2 3 1 No
No

result:

wrong answer Token parameter [name=yesno] equals to "2", doesn't correspond to pattern "Yes|No" (test case 2)