QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549540 | #860. We apologize for any inconvenience | Rafat_Kabir | AC ✓ | 3215ms | 21268kb | C++20 | 4.7kb | 2024-09-06 17:16:54 | 2024-09-06 17:16:55 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod = 1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout << asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout << asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >> asdafas;
#define finAll(A) for(auto &asdafas : A) fin >> asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll>
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
//#define MAXN 1000000
void solve(int it)
{
int n, k;
// scanf("%d%d", &n, &k);
cin >> n >> k;
vv64 dp(n+k, v64(n+k, inf));
FOR(0, n - 1, i) dp[i][i] = 0;
FOR(0, k - 1, i){
int r; cin >> r;
FOR(0, r - 1, j){
ll x;cin >> x;
--x;
dp[x][i+n] = dp[i+n][x] = 1;
}
// FOR(0, i-1, j){
// dp[i+n][j+n] = dp[j+n][i+n] = 1;
// }
}
int s;
// scanf("%d", &s);
cin >> s;
v32 pos(k,-1);
FOR(0, s - 1, i){
ll id;
// scanf("%d", &id);
cin >> id;
--id;
pos[id] = s-i;
}
v32 A(n+k);
iota(all(A), 0);
// coutAll(pos);
sort(A.begin()+n, A.begin()+n+k, [&](int a, int b){
return pos[a-n] < pos[b-n];
});
// FOR(n, n+k-1, i) cout << A[i]+1-n << " ";
// cout << "\n";
// coutAll(A);
v64 ans(s+1, 0);
// cout << "done\n";
FOR(0, n+k-1, l){
ll mx = 0;
if(A[l]-n >= 0 && pos[A[l]-n] != -1){
// cout << s+1-pos[A[l]-n] << "->";
FOR(0, n-1, i){
FOR(0, n - 1, j){
if(dp[i][j] == inf) continue;
if(dp[i][j] > 0)
mx = max(mx, dp[i][j]/2-1);
}
}
ans[s+1-pos[A[l]-n]] = mx;
}
FOR(0, n+k-1, i){
FOR(0, n+k-1, j){
if(dp[A[i]][A[l]] == inf) continue;
if(dp[A[l]][A[j]] == inf) continue;
if(dp[A[i]][A[j]] <= dp[A[i]][A[l]] + dp[A[l]][A[j]]) continue;
dp[A[i]][A[j]] = dp[A[i]][A[l]] + dp[A[l]][A[j]];
}
}
}
// cout <<"\n";
// coutAll(ans);
FOR(0, n-1, i){
FOR(0, n - 1, j){
if(dp[i][j] == inf) continue;
ans[0] = max(ans[0], dp[i][j]/2-1);
}
}
for(auto x : ans) cout << x << "\n";
}
int main()
{
// fast_cin();
ll t = 1;
cin >> t;
for(int it=1; it<=t; it++)
{
//cout << "Case " << it << ": ";
solve(it);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 0
Accepted
time: 48ms
memory: 4556kb
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:
1 1 1 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 1 2 2 2 2 2 2 1 1 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 ...
result:
ok 893 numbers
Test #3:
score: 0
Accepted
time: 3215ms
memory: 21264kb
input:
2 750 750 2 47 500 2 51 145 2 22 531 2 22 354 2 22 727 2 25 700 2 7 159 2 42 356 2 57 727 2 28 237 2 57 714 2 68 511 2 29 81 2 65 318 2 43 91 2 65 488 2 68 549 2 16 310 2 30 618 2 6 105 2 7 468 2 34 253 2 51 155 2 21 205 2 22 470 2 36 642 2 17 649 2 66 229 2 10 409 2 65 105 2 21 395 2 51 552 2 25 55...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 2081ms
memory: 21268kb
input:
4 750 750 2 511 512 2 649 650 2 154 155 2 128 129 2 344 345 2 453 454 2 613 614 2 10 11 2 491 492 2 356 357 2 299 300 2 294 295 2 699 700 2 441 442 2 13 14 2 78 79 2 583 584 2 430 431 2 342 343 2 63 64 2 547 548 2 100 101 2 584 585 2 14 15 2 33 34 2 619 620 2 2 3 2 392 393 2 383 384 2 631 632 2 614 ...
output:
748 695 444 444 444 444 326 326 326 257 257 257 162 162 162 152 152 152 152 152 93 93 93 93 93 93 93 93 93 93 93 93 93 72 72 72 72 72 72 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 49 49 48 48 48 48 48 48 48 48 48 48 48 48 48 48 42 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 33 26 26 26 26 26 2...
result:
ok 997 numbers
Test #5:
score: 0
Accepted
time: 3198ms
memory: 21260kb
input:
2 750 750 540 514 18 412 670 208 26 633 215 378 588 530 101 563 276 247 697 596 328 83 129 494 13 298 582 269 222 649 57 14 365 325 419 679 579 747 583 97 571 744 632 61 622 681 67 127 624 524 399 216 589 275 644 271 442 447 444 460 184 118 542 290 746 613 704 25 353 477 364 715 292 294 224 201 512 ...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 1500ms
memory: 11416kb
input:
2 498 498 164 139 208 482 253 14 37 20 228 198 467 39 174 48 288 353 155 190 246 119 455 76 149 167 128 375 183 415 373 212 425 36 161 304 348 310 204 497 231 399 490 324 211 475 340 309 24 58 151 166 471 443 321 286 67 473 251 219 383 277 176 142 171 82 86 136 427 235 278 498 343 23 391 85 60 110 2...
output:
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 996 numbers
Test #7:
score: 0
Accepted
time: 1647ms
memory: 11720kb
input:
2 500 500 2 1 2 2 2 1 2 3 4 2 4 3 2 5 6 2 6 5 2 7 8 2 8 7 2 9 10 2 10 9 2 11 12 2 12 11 2 13 14 2 14 13 2 15 16 2 16 15 2 17 18 2 18 17 2 19 20 2 20 19 2 21 22 2 22 21 2 23 24 2 24 23 2 25 26 2 26 25 2 27 28 2 28 27 2 29 30 2 30 29 2 31 32 2 32 31 2 33 34 2 34 33 2 35 36 2 36 35 2 37 38 2 38 37 2 39...
output:
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000 numbers