QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22556 | #2848. 城市地铁规划 | blackswallow# | RE | 20ms | 3904kb | C++20 | 2.4kb | 2022-03-09 20:15:23 | 2022-04-30 01:20:18 |
Judging History
answer
//Code By CXY07 - It's My Fiesta.
#include<bits/stdc++.h>
using namespace std;
//#define FILE
#define int long long
#define randint(l, r) (rand() % ((r) - (l) + 1) + (l))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define popc(x) __builtin_popcount(x)
#define inv(x) qpow((x), mod - 2)
#define lowbit(x) ((x) & (-(x)))
#define ull unsigned long long
#define pii pair<int, int>
#define LL long long
#define mp make_pair
#define pb push_back
#define scd second
#define vec vector
#define fst first
#define endl '\n'
#define y1 _y1
const int MAXN = 6010;
const int INF = 2e9;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 59393;
//const int mod = 998244353;
//const int G = 3;
//const int base = 131;
int n, k, m, Ans;
int dp[MAXN], a[15], coef[MAXN];
int pre[MAXN], d[MAXN];
template<typename T> inline bool read(T &a) {
a = 0; char c = getchar(); int f = 1;
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { a = a * 10 + (c ^ 48); c = getchar(); }
return a *= f, true;
}
template<typename A, typename ...B>
inline bool read(A &x, B &...y) { return read(x) && read(y...); }
int f(int x) {
int res = 0;
for(int i = k; i >= 0; --i)
res = (res * x + a[i]) % mod;
return res;
}
void GetPrufer() {
int t[MAXN], cnt = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= d[i]; ++j)
t[++cnt] = i;
priority_queue<int> Q; while(Q.size()) Q.pop();
for(int i = 1; i <= n; ++i)
if(!d[i]) Q.push(-i);
for(int i = 1; i <= cnt; ++i) {
int x = -Q.top(); Q.pop();
printf("%lld %lld\n", x, t[i]);
--d[t[i]];
if(!d[t[i]]) Q.push(-t[i]);
}
assert((int)Q.size() == 2);
printf("%lld ", -Q.top()); Q.pop();
printf("%lld\n", -Q.top()); Q.pop();
}
signed main () {
#ifdef FILE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
read(n), read(k); m = n - 2;
for(int i = 0; i <= k; ++i) read(a[i]);
int tmp = f(1); coef[0] = 0;
for(int i = 1; i < n; ++i)
coef[i] = f(i + 1) - tmp;
Ans += tmp * n;
memset(dp, -0x3f, sizeof dp); dp[0] = 0;
for(int i = 0; i <= m; ++i)
for(int j = 1; j < n && i + j <= m; ++j)
if(dp[i + j] < dp[i] + coef[j]) {
dp[i + j] = dp[i] + coef[j];
pre[i + j] = i;
}
Ans += dp[m];
int p = 1, cur = m;
while(cur) {
d[p] += cur - pre[cur];
cur = pre[cur]; ++p;
}
printf("%lld %lld\n", n - 1, Ans);
GetPrufer();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
63 7 4 50 14 48 33 13 44 24
output:
62 992106 32 1 33 1 1 2 34 2 2 3 35 3 3 4 36 4 4 5 37 5 5 6 38 6 6 7 39 7 7 8 40 8 8 9 41 9 9 10 42 10 10 11 43 11 11 12 44 12 12 13 45 13 13 14 46 14 14 15 47 15 15 16 48 16 16 17 49 17 17 18 50 18 18 19 51 19 19 20 52 20 20 21 53 21 21 22 54 22 22 23 55 23 23 24 56 24 24 25 57 25 25 26 58 26 26 27...
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
208 7 23 28 14 16 46 28 26 28
output:
207 3317121 104 1 105 1 1 2 106 2 2 3 107 3 3 4 108 4 4 5 109 5 5 6 110 6 6 7 111 7 7 8 112 8 8 9 113 9 9 10 114 10 10 11 115 11 11 12 116 12 12 13 117 13 13 14 118 14 14 15 119 15 15 16 120 16 16 17 121 17 17 18 122 18 18 19 123 19 19 20 124 20 20 21 125 21 21 22 126 22 22 23 127 23 23 24 128 24 24...
result:
ok
Test #3:
score: 0
Accepted
time: 20ms
memory: 3892kb
input:
2928 3 27 20 7 29
output:
2927 13889888 267 1 268 1 269 1 270 1 271 1 272 1 273 1 274 1 275 1 276 1 277 1 1 2 278 2 279 2 280 2 281 2 282 2 283 2 284 2 285 2 286 2 287 2 2 3 288 3 289 3 290 3 291 3 292 3 293 3 294 3 295 3 296 3 297 3 3 4 298 4 299 4 300 4 301 4 302 4 303 4 304 4 305 4 306 4 307 4 4 5 308 5 309 5 310 5 311 5 ...
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
320 3 46 42 15 15
output:
319 1260206 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 1 2 38 2 39 2 40 2 41 2 42 2 43 2 44 2 45 2 46 2 47 2 48 2 49 2 50 2 2 3 51 3 52 3 53 3 54 3 55 3 56 3 57 3 58 3 59 3 60 3 61 3 62 3 63 3 3 4 64 4 65 4 66 4 67 4 68 4 69 4 70 4 71 4 72 4 73 4 74 4 75 4 76 4 4 5 77 5 78...
result:
ok
Test #5:
score: 0
Accepted
time: 3ms
memory: 3840kb
input:
380 5 41 27 8 3 31 0
output:
379 3140470 77 1 78 1 79 1 80 1 81 1 1 2 82 2 83 2 84 2 85 2 2 3 86 3 87 3 88 3 89 3 3 4 90 4 91 4 92 4 93 4 4 5 94 5 95 5 96 5 97 5 5 6 98 6 99 6 100 6 101 6 6 7 102 7 103 7 104 7 105 7 7 8 106 8 107 8 108 8 109 8 8 9 110 9 111 9 112 9 113 9 9 10 114 10 115 10 116 10 117 10 10 11 118 11 119 11 120 ...
result:
ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 3840kb
input:
365 5 35 20 24 29 3 25
output:
364 3508667 122 1 123 1 124 1 1 2 125 2 126 2 2 3 127 3 128 3 3 4 129 4 130 4 4 5 131 5 132 5 5 6 133 6 134 6 6 7 135 7 136 7 7 8 137 8 138 8 8 9 139 9 140 9 9 10 141 10 142 10 10 11 143 11 144 11 11 12 145 12 146 12 12 13 147 13 148 13 13 14 149 14 150 14 14 15 151 15 152 15 15 16 153 16 154 16 16 ...
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
318 6 4 44 46 6 37 14 49
output:
317 6799456 159 1 160 1 1 2 161 2 2 3 162 3 3 4 163 4 4 5 164 5 5 6 165 6 6 7 166 7 7 8 167 8 8 9 168 9 9 10 169 10 10 11 170 11 11 12 171 12 12 13 172 13 13 14 173 14 14 15 174 15 15 16 175 16 16 17 176 17 17 18 177 18 18 19 178 19 19 20 179 20 20 21 180 21 21 22 181 22 22 23 182 23 23 24 183 24 24...
result:
ok
Test #8:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
416 6 30 23 4 16 45 32 19
output:
415 5383994 208 1 209 1 1 2 210 2 2 3 211 3 3 4 212 4 4 5 213 5 5 6 214 6 6 7 215 7 7 8 216 8 8 9 217 9 9 10 218 10 10 11 219 11 11 12 220 12 12 13 221 13 13 14 222 14 14 15 223 15 15 16 224 16 16 17 225 17 17 18 226 18 18 19 227 19 19 20 228 20 20 21 229 21 21 22 230 22 22 23 231 23 23 24 232 24 24...
result:
ok
Test #9:
score: 0
Accepted
time: 3ms
memory: 3844kb
input:
572 5 15 27 5 18 3 46
output:
571 9396678 191 1 192 1 193 1 1 2 194 2 195 2 2 3 196 3 197 3 3 4 198 4 199 4 4 5 200 5 201 5 5 6 202 6 203 6 6 7 204 7 205 7 7 8 206 8 207 8 8 9 208 9 209 9 9 10 210 10 211 10 10 11 212 11 213 11 11 12 214 12 215 12 12 13 216 13 217 13 13 14 218 14 219 14 14 15 220 15 221 15 15 16 222 16 223 16 16 ...
result:
ok
Test #10:
score: 0
Accepted
time: 3ms
memory: 3844kb
input:
531 8 20 13 35 27 41 43 36 25 5
output:
530 9024252 178 1 179 1 180 1 1 2 181 2 182 2 2 3 183 3 184 3 3 4 185 4 186 4 4 5 187 5 188 5 5 6 189 6 190 6 6 7 191 7 192 7 7 8 193 8 194 8 8 9 195 9 196 9 9 10 197 10 198 10 10 11 199 11 200 11 11 12 201 12 202 12 12 13 203 13 204 13 13 14 205 14 206 14 14 15 207 15 208 15 15 16 209 16 210 16 16 ...
result:
ok
Test #11:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
487 10 29 29 40 45 5 16 40 47 47 2 14
output:
486 18026623 486 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
result:
ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
584 7 10 27 29 8 32 43 26 3
output:
583 11437238 292 1 293 1 1 2 294 2 2 3 295 3 3 4 296 4 4 5 297 5 5 6 298 6 6 7 299 7 7 8 300 8 8 9 301 9 9 10 302 10 10 11 303 11 11 12 304 12 12 13 305 13 13 14 306 14 14 15 307 15 15 16 308 16 16 17 309 17 17 18 310 18 18 19 311 19 19 20 312 20 20 21 313 21 21 22 314 22 22 23 315 23 23 24 316 24 2...
result:
ok
Test #13:
score: 0
Accepted
time: 2ms
memory: 3836kb
input:
59 4 48 16 9 42 21
output:
58 422967 12 1 13 1 14 1 15 1 16 1 17 1 18 1 1 2 19 2 20 2 21 2 22 2 2 3 23 3 24 3 25 3 26 3 3 4 27 4 28 4 29 4 30 4 4 5 31 5 32 5 33 5 34 5 5 6 35 6 36 6 37 6 38 6 6 7 39 7 40 7 41 7 42 7 7 8 43 8 44 8 45 8 46 8 8 9 47 9 48 9 49 9 50 9 9 10 51 10 52 10 53 10 54 10 10 11 55 11 56 11 57 11 58 11 11 59
result:
ok
Test #14:
score: 0
Accepted
time: 3ms
memory: 3760kb
input:
561 3 22 31 17 49
output:
560 3223790 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 1 2 73 2 74 2 75 2 76 2 77 2 78 2 79 2 80 2 2 3 81 3 82 3 83 3 84 3 85 3 86 3 87 3 88 3 3 4 89 4 90 4 91 4 92 4 93 4 94 4 95 4 96 4 4 5 97 5 98 5 99 5 100 5 101 5 102 5 103 5 104 5 5 6 105 6 106 6 107 6 108 6 109 6 110 6 111 6 112 6 6 7 113 7 ...
result:
ok
Test #15:
score: 0
Accepted
time: 3ms
memory: 3904kb
input:
629 6 26 31 41 32 13 39 41
output:
628 13149156 315 1 316 1 1 2 317 2 2 3 318 3 3 4 319 4 4 5 320 5 5 6 321 6 6 7 322 7 7 8 323 8 8 9 324 9 9 10 325 10 10 11 326 11 11 12 327 12 12 13 328 13 13 14 329 14 14 15 330 15 15 16 331 16 16 17 332 17 17 18 333 18 18 19 334 19 19 20 335 20 20 21 336 21 21 22 337 22 22 23 338 23 23 24 339 24 2...
result:
ok
Test #16:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
616 3 38 48 27 2
output:
615 1394108 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 1 2 51 2 52 2 53 2 54 2 55 2 56 2 57 2 58 2 59 2 60 2 61 2 62 2 63 2 64 2 65 2 66 2 67 2 68 2 69 2 70 2 71 2 72 2 73 2 74 2 2 3 75 3 76 3 77 3 78 3 79 3 80 3 81 3 ...
result:
ok
Test #17:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
744 2 49 45 50
output:
743 1425426 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 1 2 57 2 58 2 59 2 60 2 61 2 62 2 63 2 64 2 65 2 66 2 67 2 68 2 69 2 70 2 71 2 72 2 73 2 74 2 75 2 76 2 77 2 78 2 79 2 80 2...
result:
ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
629 7 27 18 48 24 37 38 6 3
output:
628 9258317 159 1 160 1 161 1 162 1 1 2 163 2 164 2 165 2 2 3 166 3 167 3 168 3 3 4 169 4 170 4 171 4 4 5 172 5 173 5 174 5 5 6 175 6 176 6 177 6 6 7 178 7 179 7 180 7 7 8 181 8 182 8 183 8 8 9 184 9 185 9 186 9 9 10 187 10 188 10 189 10 10 11 190 11 191 11 192 11 11 12 193 12 194 12 195 12 12 13 19...
result:
ok
Test #19:
score: 0
Accepted
time: 3ms
memory: 3764kb
input:
602 8 17 25 14 13 2 16 23 24 44
output:
601 9947756 601 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51...
result:
ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
900 2 9 13 12
output:
899 787522 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1...
result:
ok
Test #21:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
839 7 12 12 28 33 35 29 14 17
output:
838 24516016 420 1 421 1 1 2 422 2 2 3 423 3 3 4 424 4 4 5 425 5 5 6 426 6 6 7 427 7 7 8 428 8 8 9 429 9 9 10 430 10 10 11 431 11 11 12 432 12 12 13 433 13 13 14 434 14 14 15 435 15 15 16 436 16 16 17 437 17 17 18 438 18 18 19 439 19 19 20 440 20 20 21 441 21 21 22 442 22 22 23 443 23 23 24 444 24 2...
result:
ok
Test #22:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
768 7 27 3 40 6 39 9 48 31
output:
767 18960055 384 1 385 1 1 2 386 2 2 3 387 3 3 4 388 4 4 5 389 5 5 6 390 6 6 7 391 7 7 8 392 8 8 9 393 9 9 10 394 10 10 11 395 11 11 12 396 12 12 13 397 13 13 14 398 14 14 15 399 15 15 16 400 16 16 17 401 17 17 18 402 18 18 19 403 19 19 20 404 20 20 21 405 21 21 22 406 22 22 23 407 23 23 24 408 24 2...
result:
ok
Test #23:
score: 0
Accepted
time: 4ms
memory: 3848kb
input:
783 3 25 19 31 45
output:
782 4263811 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 1 2 97 2 98 2 99 2 100 2 101 2 102 2 103 2 104 2 2 3 105 3 106 3 107 3 108 3 109 3 110 3 111 3 112 3 3 4 113 4 114 4 115 4 116 4 117 4 118 4 119 4 120 4 4 5 121 5 122 5 123 5 124 5 125 5 126 5 127 5 128 5 5 6 129 6 130 6 131 6 132 6 133 6 134 ...
result:
ok
Test #24:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
2 4 24 9 31 45 15
output:
1 248 1 2
result:
ok
Test #25:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
792 5 28 40 21 32 44 11
output:
791 6695732 265 1 266 1 267 1 1 2 268 2 269 2 2 3 270 3 271 3 3 4 272 4 273 4 4 5 274 5 275 5 5 6 276 6 277 6 6 7 278 7 279 7 7 8 280 8 281 8 8 9 282 9 283 9 9 10 284 10 285 10 10 11 286 11 287 11 11 12 288 12 289 12 12 13 290 13 291 13 13 14 292 14 293 14 14 15 294 15 295 15 15 16 296 16 297 16 16 ...
result:
ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
939 5 35 7 31 40 25 28
output:
938 12031060 313 1 314 1 315 1 316 1 1 2 317 2 318 2 2 3 319 3 320 3 3 4 321 4 322 4 4 5 323 5 324 5 5 6 325 6 326 6 6 7 327 7 328 7 7 8 329 8 330 8 8 9 331 9 332 9 9 10 333 10 334 10 10 11 335 11 336 11 11 12 337 12 338 12 12 13 339 13 340 13 13 14 341 14 342 14 14 15 343 15 344 15 15 16 345 16 346...
result:
ok
Test #27:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
924 6 30 26 21 8 12 42 26
output:
923 14203740 462 1 463 1 1 2 464 2 2 3 465 3 3 4 466 4 4 5 467 5 5 6 468 6 6 7 469 7 7 8 470 8 8 9 471 9 9 10 472 10 10 11 473 11 11 12 474 12 12 13 475 13 13 14 476 14 14 15 477 15 15 16 478 16 16 17 479 17 17 18 480 18 18 19 481 19 19 20 482 20 20 21 483 21 21 22 484 22 22 23 485 23 23 24 486 24 2...
result:
ok
Test #28:
score: 0
Accepted
time: 3ms
memory: 3764kb
input:
902 8 8 48 35 25 32 28 21 2 44
output:
901 13244886 901 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
result:
ok
Test #29:
score: 0
Accepted
time: 3ms
memory: 3872kb
input:
1021 2 11 16 14
output:
1020 977447 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 ...
result:
ok
Test #30:
score: -100
Dangerous Syscalls
input:
1 9 18 7 32 20 44 12 15 38 14 43