QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201788 | #7523. Partially Free Meal | oscaryang | WA | 116ms | 19360kb | C++14 | 2.4kb | 2023-10-05 16:45:57 | 2023-10-05 16:45:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define mkp make_pair
#define pii pair<int,int>
#define vc vector
#define pb emplace_back
#define mem(a) memset(a,0,sizeof(a))
//#define int long long
const int N = 5e5+5, P = 1e9+7;
const int inf = 0x3f3f3f3f;
//const ll inf = 0x3f3f3f3f3f3f3f3f;
mt19937 gen(time(0));
//in&out
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch=='-'), ch = getchar();
while(isdigit(ch)) x = (x*10)+(ch^48), ch=getchar(); return w?-x:x;
}
inline void write(int x) { if(x<0) putchar('-'), x = -x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void writec(int x) { write(x); putchar(32); }
inline void writee(int x) { write(x); putchar(10); }
//calc
inline void inc(int &x,int y) { x += y-P; x += (x>>31)&P; }
inline void dec(int &x,int y) { x -= y; x += (x>>31)&P; }
inline int pls(int x,int y) { x += y-P; x += (x>>31)&P; return x; }
inline void Max(int &x,int y) { if(x<y) x = y; }
inline void Min(int &x,int y) { if(x>y) x = y; }
inline int power(int a,int b) { int res = 1; for(;b;b >>= 1,a = 1ll*a*a%P) if(b&1) res = 1ll*res*a%P; return res; }
int n;
pii a[N];
ll f[N], g[N], dp[N], lf, lg, ldp;
inline void merge(int l, int r, int L, int R) {
int mid = l + r >> 1, p = -1; dp[mid] = inf;
for(int i = L, j = mid - L; i <= R; i++, j--) if(j >= 0 && j <= lg && g[j] + f[i] < dp[mid])
dp[mid] = g[j] + f[i], p = i;
if(l < r) merge(l, mid, L, p), merge(mid + 1, r, p, R);
}
inline vc<ll> solve(int l, int r) {
if(l == r) {
vc<ll> res(2); res[1] = a[l].first + a[l].second;
return res;
}
int mid = l + r >> 1;
auto R = solve(mid + 1, r); lf = R.size() - 1; g[lg = 0] = 0;
for(int i = 0; i <= lf; i++) f[i] = R[i];
for(int i = l; i <= mid; i++) g[++lg] = a[i].second;
sort(g + 1, g + 1 + lg);
for(int i = 1; i <= lg; i++) g[i] += g[i - 1];
merge(1, ldp = r - l + 1, 1, lf);
vc<ll> res(ldp + 1, 0);
for(int i = 0; i <= ldp; i++) res[i] = dp[i];
auto L = solve(l, mid);
for(int i = 0; i < L.size(); i++) res[i] = min(res[i], L[i]);
return res;
}
signed main() {
n = read();
for(int i = 1; i <= n; i++) a[i].second = read(), a[i].first = read();
sort(a + 1, a + 1 + n);
auto ans = solve(1, n);
for(int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9816kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 116ms
memory: 19360kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
6242903 16281 28807 46033 65614 89014 116268 163351 214238 269247 342691 416209 490664 567726 655826 748986 844781 946658 1057821 1169657 1291729 1420453 1570394 1726012 1888357 2052308 2217841 2393432 2572053 2766048 2966349 3167219 3377027 3594282 3836353 4086900 4338454 4592096 4847496 5102975 53...
result:
wrong answer 1st lines differ - expected: '1318594', found: '6242903'