QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789727 | #7078. Tower of the Sorcerer | Richard | WA | 197ms | 277064kb | C++17 | 2.4kb | 2024-11-27 21:36:27 | 2024-11-27 21:36:32 |
Judging History
answer
#include <bits/stdc++.h>
#define int LL
#define rrr 100000
#define inf 1000000000000000007LL
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
typedef long long LL;
const int N = 1e5+5;
int n, a, mxa, aa[N], hh[N];
vector <int> ah[N];
LL ans, ret, dp[N];
struct qwq { int k; LL b; };
deque <qwq> tr[N<<2];
template <typename T> inline void debug(T x) { cerr<<x; }
template <typename T, typename ...T_> inline void debug(T x, T_ ...p) { cerr<<x<<' ', debug(p...); }
template <typename T> void read(T& x) {
x = 0; int f = 0; char c = getchar();
while(c < '0' || c > '9') f |= (c == '-'), c=getchar();
while(c >= '0' && c <= '9') x=(x<<1)+(x<<3)+(c^48), c=getchar();
x=(f ? -x : x);
}
int lne; char put[105];
template <typename T> void write(T x, char ch) {
lne = 0; if(x < 0) putchar('-'), x=-x;
do { put[++lne]=x%10, x/=10; } while(x);
while(lne) putchar(put[lne--]^48);
putchar(ch);
}
#define ls (k<<1)
#define rs (ls|1)
int check(qwq A, qwq B, qwq C) {
return (1LL*(B.b-A.b)*(A.k-C.k) >= 1LL*(C.b-A.b)*(A.k-B.k));
}
void updt(int k, int l, int r, int to, qwq w) {
while(tr[k].size() > 1 && check(*tr[k].rbegin(), *(++tr[k].rbegin()), w))
tr[k].pop_back();
tr[k].push_back(w);
if(l == r)
return ;
int mid = ((l+r)>>1);
if(to <= mid)
updt(ls, l, mid, to, w);
else
updt(rs, mid+1, r, to, w);
}
LL www(qwq w, int xx) {
return 1LL*xx*w.k+w.b;
}
void ask(int k, int l, int r, int lq, int rq, int xx) {
if(lq <= l && r <= rq) {
while(tr[k].size() > 1 && www(*tr[k].begin(), xx) >= www(*(++tr[k].begin()), xx))
tr[k].pop_front();
if(!tr[k].empty())
ret=min(ret, www(*tr[k].begin(), xx));
return;
}
int mid = ((l+r)>>1);
if(lq <= mid)
ask(ls, l, mid, lq, rq, xx);
if(mid < rq)
ask(rs, mid+1, r, lq, rq, xx);
}
signed main() {
read(n), read(a), mxa=a;
for(int i = 1; i <= n; ++i)
read(aa[i]), read(hh[i]), mxa=max(mxa, aa[i]), ah[aa[i]].push_back(hh[i]);
for(int i = 1; i <= n; ++i)
ans+=1LL*(hh[i]-1)/mxa*aa[i];
for(int i = mxa; i >= a; --i) {
ret=(i == mxa ? 0LL : inf);
for(int xx = 0, l = 1, r = i; l <= rrr; ++xx, l+=i, r+=i)
ask(1, 1, rrr, l, min((LL) rrr, r), xx);
dp[i]=ret;
for(int j = 0; j < ah[i].size(); ++j)
updt(1, 1, rrr, ah[i][j], qwq {i, dp[i]-1LL*(ah[i][j]-1)/mxa*i});
}
// debug(ans, "???\n");
write(dp[a]+ans, '\n');
return 0;
}
/*
4 1
3 2
4 4
5 6
1 6
9
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 52ms
memory: 277064kb
input:
4 1 3 2 4 4 5 6 1 6
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 143ms
memory: 275636kb
input:
5000 679 84191 46042 81916 66659 74636 72443 10252 57443 21838 54620 84896 58466 20832 29643 45949 20576 50399 51434 56472 90759 68909 94348 39459 1731 81207 17614 26465 11775 93861 24936 25017 64663 21042 37570 32903 68583 68840 58347 93849 10841 10190 77131 10595 1959 57163 59047 16066 89850 73741...
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 152ms
memory: 276196kb
input:
5000 685 67283 21828 19841 367 69908 57925 63894 10753 20139 20595 672 47788 81010 57483 53755 96758 85049 78636 94198 12795 97299 86489 57399 56590 30519 63514 92072 5714 60572 8651 25620 13514 27482 51652 88352 27272 4391 23458 43759 57471 95084 88191 53782 96875 52546 33731 95458 5643 75049 42685...
output:
60515
result:
ok single line: '60515'
Test #4:
score: 0
Accepted
time: 150ms
memory: 276460kb
input:
5000 883 57988 4889 27548 3497 47774 97848 73725 83535 43075 12741 86312 87522 98386 29435 88105 19813 50656 83340 32721 37465 84421 14671 92169 37187 33163 53370 95155 35577 63396 86337 20931 57282 80964 12797 84905 95122 7530 7623 1393 58436 9609 91063 92309 31959 37789 98189 74209 33091 64400 530...
output:
142420
result:
ok single line: '142420'
Test #5:
score: 0
Accepted
time: 184ms
memory: 277032kb
input:
5000 110 81857 71124 57698 64343 80952 96284 15190 95432 51153 64223 39943 25603 77013 72711 94708 24951 64786 9225 54307 29867 2166 9420 38155 28813 96118 90751 85381 30858 17457 43971 38450 20480 36831 31955 86436 3116 71718 45322 2141 92627 36585 66945 8885 99790 49929 5604 25126 14766 78673 4804...
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 139ms
memory: 275976kb
input:
5000 852 68512 97389 60972 88659 73325 90709 87906 83485 39089 40758 25295 95321 61154 18959 19137 97232 40721 17563 3359 33010 484 29851 3964 60841 88065 81476 1622 35273 28703 97697 72577 9099 16043 92977 37261 95232 41086 16776 38139 94039 79650 24363 30987 95332 81397 67793 52508 71034 22631 725...
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 197ms
memory: 276588kb
input:
5000 23 49957 100000 97978 100000 66997 100000 70406 100000 62250 100000 71093 100000 14758 100000 59859 100000 81605 100000 50139 100000 97303 100000 23626 100000 38523 100000 5028 100000 59461 100000 99559 100000 5150 100000 21343 100000 5738 100000 81487 100000 87427 100000 67101 100000 8692 1000...
output:
265915027
result:
wrong answer 1st lines differ - expected: '251733189', found: '265915027'