QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415546 | #860. We apologize for any inconvenience | Atalasion# | WA | 12ms | 8492kb | C++14 | 2.5kb | 2024-05-20 23:18:07 | 2024-05-20 23:18:09 |
Judging History
answer
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 750 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
const int H = 313;
int n, k, mark[N], mark2[N][N], d[N][N];
vi com[N];
vi tot_com[N];
queue<int> q[N];
void solve(int v){
while(q[v].size()){
int fr = q[v].front();
q[v].pop();
for (auto u:tot_com[fr]){
if (d[v][u] > d[v][fr] + 1){
d[v][u] = d[v][fr] + 1;
q[v].push(u);
}
}
}
return;
}
int calc(){
int mx = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if (d[i][j] <= k) mx = max(mx, d[i][j]);
}
}
return mx;
}
void Main(){
cin >> n >> k;
memset(mark, 0, sizeof mark);
for (int i = 0; i < N; i++) com[i].clear();
for (int i = 0; i < N; i++) tot_com[i].clear();
memset(d, 31, sizeof d);
for (int i = 1; i <= k; i++){
int t;
cin >> t;
for (int j = 0; j < t; j++){
int x;
cin >> x;
com[i].pb(x);
}
}
vi Q;
int s;
cin >> s;
for (int i = 0; i < s; i++){
int x;
cin >> x;
Q.pb(x);
mark[x] = 1;
}
for (int i = 1; i <= k; i++){
if (mark[i] == 0){
for (int j = 0; j < com[i].size(); j++){
for (int l = j + 1; l < com[i].size(); l++){
mark2[com[i][j]][com[i][l]] = 1;
mark2[com[i][l]][com[i][j]] = 1;
}
}
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if (mark2[i][j]) tot_com[i].pb(j);
}
}
for (int i = 1; i <= n; i++) {d[i][i] = -1; q[i].push(i);}
for (int i = 1; i <= n; i++)solve(i);
vi ans;
ans.pb(calc());
for (int i = s - 1; i >= 0; i--){
int v = Q[i];
memset(mark, 0, sizeof mark);
for (auto u:com[v]){
mark[u] = 1;
}
for (int j = 1; j <= n; j++){
int mn = d[j][com[v][0]];
int ki = com[v][0];
for (auto u:com[v]){
if (mn > d[j][u]){
mn = d[j][u];
ki = u;
}
}
for (auto u:com[v]){
if (d[j][u] > mn + 1){
d[j][u] = mn + 1;
q[j].push(u);
}
}
solve(j);
}
ans.pb(calc());
}
reverse(all(ans));
for (auto u:ans)cout << u << '\n';
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--){
Main();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7664kb
input:
1 5 4 3 1 3 5 2 1 4 2 2 3 2 2 4 3 1 4 3
output:
1 2 0 0
result:
ok 4 number(s): "1 2 0 0"
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 8492kb
input:
35 20 20 2 2 13 2 2 9 7 10 3 9 15 5 11 4 9 16 19 15 4 17 18 5 3 8 8 12 20 16 11 18 9 6 4 12 4 18 15 17 6 16 19 14 7 5 20 9 3 8 14 4 5 14 7 9 17 5 3 17 11 20 15 19 11 16 5 8 13 15 20 18 9 10 14 7 4 3 13 19 10 17 6 8 15 9 4 12 20 7 14 16 5 4 12 11 6 18 14 20 17 18 4 8 15 11 16 14 6 5 13 19 3 8 3 10 8 ...
output:
2 2 2 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2 2 2 2 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '1', found: '2'