QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#388760 | #8005. Crossing the Border | RedreamMer | TL | 4996ms | 205340kb | C++17 | 3.4kb | 2024-04-13 19:27:56 | 2024-04-13 19:27:56 |
Judging History
answer
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define PB emplace_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) { rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1]; }
const int N = 22, mod = 998244353, inf = 1e12;
int a, b, s[1 << N], w[1 << N], now[1 << N];
struct pii {
int x, y;
pii (int _x = inf, int _y = 0) {x = _x, y = _y;}
pii operator+(const int &o) const {return pii(x + o, y);}
pii operator+(const pii &o) const {
if(x < o.x) return pii(x, y);
else if(x > o.x) return o;
return pii(x, (y + o.y) % mod);
}
} f[1 << N], c[N], val[1 << N];
vector<pii> q, p[1 << (N >> 1)];
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
rep(i, 0, a - 1) cin >> c[i].x >> c[i].y;
sort(c, c + a, [&] (pii x, pii y) {
return x.y < y.y;
});
rep(i, 0, a - 1) s[1 << i] = c[i].x, w[1 << i] = c[i].y;
rep(i, 1, (1 << a) - 1) {
int j = i & -i;
if(i != j) s[i] = s[i ^ j] + s[j], w[i] = w[i ^ j];
}
int d = a / 2, e = a - d;
f[0] = pii {0, 1};
rep(i, 1, (1 << a) - 1) {
int st = i & ((1 << d) - 1);
for(int j = st; j; j = (j - 1) & st) if(s[j] <= b && (st & -st) == (j & -j))
f[i] = f[i] + (f[i ^ j] + w[j]);
}
rep(i, 1, (1 << a) - 1) {
int st = i >> d;
for(int j = st; j; j = (j - 1) & st) if(s[j << d] <= b && (st & -st) == (j & -j))
f[i] = f[i] + (f[i ^ (j << d)] + w[j << d]);
}
// cout << f[3].x << endl;
rep(i, 0, (1 << d) - 1) {
for(int j = i; j; j = (j - 1) & i) p[i].PB(pii(j, s[j]));
sort(p[i].begin(), p[i].end(), [&] (pii x, pii y) {
return x.y < y.y;
});
}
// if(a >= 18) {
// cout << f[(1 << a) - 1].x << ' ' << f[(1 << a) - 1].y;
// return 0;
// }
rep(i, 0, (1 << e) - 1) {
q.clear();
int st = i ^ ((1 << e) - 1);
for(int j = st; j; j = (j - 1) & st) if(__builtin_clz(st) == __builtin_clz(j)) q.PB(pii(j, s[j << d]));
sort(q.begin(), q.end(), [&] (pii x, pii y) {
return x.y > y.y;
});
rep(j, 0, (1 << d) - 1) now[j] = 0, val[j] = pii();
for(auto [v, w] : q) {
// cerr << i << ' ' << w << endl;
// if(i == 0 && v == 4) cerr << "#@#@2" << endl;
rep(j, 0, (1 << d) - 1) {
for(; now[j] < siz(p[j]) && p[j][now[j]].y + w <= b; ++now[j]) {
// cerr << "#@!@!" << endl;
val[j] = val[j] + (f[(i << d) | (j ^ p[j][now[j]].x)] + ::w[v << d]);
// cout << val[j].x << ' ' << val[j].y << endl;
}
// if(i == 3 && v == 4 && j == 3) cerr << "#@#@" << ((v | i) << d | j) << ' ' << val[j].x << endl;
// if(((v | i) << d | j) == (1 << a) - 1) cerr << (val[j]).x << endl;
f[((v | i) << d) | j] = f[((v | i) << d) | j] + val[j];
}
}
}
// rep(i, 1, (1 << a) - 1) {
// for(int j = i; j; j = (j - 1) & i) if(s[j] <= b)
// f[i] = f[i] + (f[i ^ j] + w[j]);
// }
// cout << f[(1 << a) - 1].x << ' ' << f[(1 << a) - 1].y;
// return 0;
cout << f[(1 << a) - 1].x << ' ' << f[(1 << a) - 1].y;
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 141244kb
input:
5 5 3 5 1 4 2 3 2 2 2 1
output:
9 4
result:
ok 2 number(s): "9 4"
Test #2:
score: 0
Accepted
time: 98ms
memory: 143976kb
input:
18 10000000 956231 904623 1692946 1796774 1081323 1170319 3218792 2542661 3183376 3037270 1869132 1442561 35436 35018 1564635 1939950 1847344 2006043 755870 899310 1671882 2057413 1369264 1338951 3132483 3504034 2056224 1825640 1840949 1562071 1514040 1405352 2300821 2421801 2466540 3004920
output:
9391997 70
result:
ok 2 number(s): "9391997 70"
Test #3:
score: 0
Accepted
time: 672ms
memory: 152556kb
input:
20 10000000 1289384 1416015 1692778 1966748 1747794 1708650 2885387 2925290 2516650 2410838 2202363 2092667 368691 407497 1897764 1902790 180541 224758 1089173 1075924 2005212 1743637 702568 566295 465783 369143 2722863 2902398 174068 150211 513930 519657 1634023 1313239 1133070 1040937 961394 11066...
output:
6331196 89
result:
ok 2 number(s): "6331196 89"
Test #4:
score: 0
Accepted
time: 1901ms
memory: 174076kb
input:
21 10000000 1432782 1230128 1693282 1456826 605524 521515 2742745 3427204 2231114 2129928 2345527 2397808 511783 521160 2041234 2313965 2323807 2603481 1232121 1410811 719508 850004 416942 495559 2180169 2579591 1580089 1786914 2317568 2292171 1514260 1143717 1348703 1495001 562052 525544 2818854 23...
output:
9336572 5
result:
ok 2 number(s): "9336572 5"
Test #5:
score: 0
Accepted
time: 4775ms
memory: 205340kb
input:
22 10000000 1562592 1176882 1693226 1513484 2293770 2757728 2612851 3010518 1971354 2392268 2475363 2035487 641627 684375 2171036 2181775 1544541 1633457 1361981 1060447 2277948 2792254 157192 141039 1011327 1139897 541119 577682 1538276 1451191 2423314 2061841 1088919 1154927 42526 43789 1779858 16...
output:
8019829 516
result:
ok 2 number(s): "8019829 516"
Test #6:
score: 0
Accepted
time: 3905ms
memory: 205204kb
input:
22 50000000 9900000 50000000 9800000 50000000 9700000 50000000 9600000 50000000 9500000 50000000 9400000 50000000 9300000 50000000 9200000 50000000 9100000 50000000 9190000 50000000 9180000 50000000 9170000 50000000 9160000 50000000 9150000 50000000 9140000 50000000 9130000 50000000 9120000 50000000...
output:
250000000 659827482
result:
ok 2 number(s): "250000000 659827482"
Test #7:
score: 0
Accepted
time: 2256ms
memory: 205332kb
input:
22 49989999 9515787 13633636 7804670 14201704 4490825 15337840 10846676 15905908 4649834 16473976 13564408 17042044 26330177 17610112 31079612 18178180 9508811 18746248 11012937 19314316 9221231 19882384 35630511 20450452 33570222 21018520 33987302 22154656 28961982 22722724 29610359 23290792 342743...
output:
297099616 239005143
result:
ok 2 number(s): "297099616 239005143"
Test #8:
score: 0
Accepted
time: 4996ms
memory: 205324kb
input:
22 49889999 4418358 4535448 7690530 4724425 3667793 4913402 8304776 5102379 2539846 5291356 2404119 5480333 2368750 5669310 3896314 5858287 6349833 6047264 10839169 6425218 10867512 6614195 9018761 6803172 5396983 6992149 2026994 7181126 6093366 7370103 10403853 7559080 5578332 7748057 13492459 7937...
output:
28157573 762
result:
ok 2 number(s): "28157573 762"
Test #9:
score: -100
Time Limit Exceeded
input:
22 48889995 670320 2222256 1480754 2407444 2099421 2592632 3936255 2777820 959515 2963008 4781765 3333384 5446683 3518572 1207621 3703760 5965481 3888948 5353960 4074136 3991352 4259324 3814761 4629700 7642867 4814888 6776227 5000076 7737927 5185264 6271909 5370452 8235670 5555640 5720862 5740828 94...