ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215176 | #2686. Oversleeping | erican | 25 | 975ms | 1164kb | C++11 | 2.3kb | 2024-11-26 22:06:13 | 2024-11-26 23:07:15 |
answer
/* Erica N */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
int xx = 0, ff = 1;char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
return xx * ff;
}
// void write(int out) {
// if (out < 0)
// putchar('-'), out = -out;
// if (out > 9)
// write(out / 10);
// putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
const int N = 3e5 + 5;
const int INF = 1e9;
const int M = 1e7;
const int MOD = 1e9 + 7;
int x,y,p,q;
bool check(int k){
int gr=floor(1.*(k*(p+q)-x)/(2*x+2*y));
int gl=ceil(1.*(k*(p+q)-x-y-q)/(2*x+2*y));
// cdbg(k,gl,gr);
return (gl<=gr);
}
void solve(){
x=rd,y=rd,p=rd,q=rd;
// if(p+q-2*x-2*y==0){
// puts("-1");
// return ;
// }
// int l=ceil(1.*x/(p+q)),r=(x+y+q)/(p+q);
int ans=INF*INF;
int l=1,r=INF;
int res=0;
// while(l<=r){
// int mid=l+r>>1;
// if(check(mid))res=mid,r=mid-1;
// else l=mid+1;
// }
for(int k=res;k<=res+200000;k++){
int gr=floor(1.*(k*(p+q)-x)/(2*x+2*y));
int gl=ceil(1.*(k*(p+q)-x-y-q)/(2*x+2*y));
if((k*(p+q)-x)/(2*x+2*y)==(k*(p+q)-x-y-q)/(2*x+2*y))continue;
// cdbg(k,gl,gr);
if(gl<=gr){
for(int g=gl;g<=gr;g++){
itn A=k*p+(k-1)*q,B=k*p+k*q,C=(2*g+1)*x+2*g*y,D=(2*g+1)*x+(2*g+1)*y;
if(max(C,A)<D)ans=min(ans,max(A,C));
}
// int g=gl;
}
}
if(ans>=INF*INF)puts("-1"); //!! INF
else cout<<ans<<endl;
}
signed main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=rd;
while(T--){
solve();
}
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 52ms
memory: 1156kb
input:
10 42 337 468 315 179 261 297 332 336 189 230 33 240 398 38 204 465 158 454 462 112 184 90 263 320 4...
output:
1558 1059 1545 1516 1711 704 1760 -400 1174 1076
result:
wrong answer 2nd lines differ - expected: '297', found: '1059'
Test #2:
score: 0
Wrong Answer
time: 54ms
memory: 1160kb
input:
10 96 471 276 491 226 87 207 365 451 201 191 173 46 375 100 8 39 179 214 269 135 260 91 431 253 288 ...
output:
1230 -365 1755 964 -269 -431 1335 374 1830 -121
result:
wrong answer 1st lines differ - expected: '276', found: '1230'
Test #3:
score: 0
Wrong Answer
time: 49ms
memory: 1160kb
input:
10 337 285 340 338 484 25 321 156 246 482 122 234 229 441 426 72 6 93 155 338 21 317 406 335 160 298...
output:
1696 5574 1702 1920 -338 697 -492 1601 2314 2744
result:
wrong answer 1st lines differ - expected: '340', found: '1696'
Test #4:
score: 0
Wrong Answer
time: 58ms
memory: 1156kb
input:
10 196 433 313 366 262 415 94 30 353 22 242 460 283 172 13 276 56 247 344 4 297 363 415 479 473 26 6...
output:
1671 1706 -397 1193 692 1617 1471 974 -377 811
result:
wrong answer 1st lines differ - expected: '313', found: '1671'
Test #5:
score: 0
Wrong Answer
time: 52ms
memory: 1156kb
input:
10 437 267 140 198 383 155 226 424 273 308 151 317 15 231 435 285 404 294 253 64 109 199 388 147 425...
output:
1845 1526 1555 -285 1838 923 2195 1641 1678 1221
result:
wrong answer 1st lines differ - expected: '478', found: '1845'
Test #6:
score: 0
Wrong Answer
time: 52ms
memory: 1160kb
input:
10 21 426 135 234 111 51 109 11 185 42 230 22 472 346 269 285 77 128 499 461 173 79 230 382 102 127 ...
output:
915 469 2001 2108 -333 -331 1018 1332 1375 996
result:
wrong answer 1st lines differ - expected: '135', found: '915'
Test #7:
score: 0
Wrong Answer
time: 45ms
memory: 1164kb
input:
10 790950658 153 395731486 328 228237805 89 805489534 371 733742769 407 150980036 116 210282811 256 ...
output:
-1 131670212810617 -1 -1 -1 -1 -1 16775085745166 -1 -1
result:
wrong answer 1st lines differ - expected: '493783472749894', found: '-1'
Test #8:
score: 0
Wrong Answer
time: 45ms
memory: 1164kb
input:
10 935151576 163 823994136 316 552819682 244 661178089 95 751586616 375 326537181 182 9424664 344 31...
output:
-1 -1 -1 1902164539224 -1 -1 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '3487138752902582', found: '-1'
Test #9:
score: 0
Wrong Answer
time: 48ms
memory: 1160kb
input:
10 480628854 293 138727635 133 188840646 190 569211831 53 442713615 341 668626439 341 527553711 268 ...
output:
-1 -1 -1 28082225856120 -1 13205465448836 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '237399557723152', found: '-1'
Test #10:
score: 0
Wrong Answer
time: 48ms
memory: 1164kb
input:
10 128375946 395 45119743 26 591869966 93 644623523 312 553967887 448 714110036 391 129391856 52 673...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 39135847964899
result:
wrong answer 1st lines differ - expected: '173096624515978', found: '-1'
Test #11:
score: 0
Wrong Answer
time: 44ms
memory: 1128kb
input:
10 416394745 108 799849287 309 285823581 120 50495267 151 984269713 448 325585187 230 502469917 398 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '510932724030159', found: '-1'
Test #12:
score: 0
Wrong Answer
time: 48ms
memory: 1160kb
input:
10 858503120 86 550141525 344 266071218 423 114926419 32 463189501 184 235629038 219 681438792 48 66...
output:
-1 14279266757365 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '1864662953909472', found: '-1'
Test #13:
score: 0
Wrong Answer
time: 48ms
memory: 1160kb
input:
10 49615553 235 484012586 439 733063300 215 529603390 181 217670208 264 477723402 451 412727927 119 ...
output:
-1 -1 -1 -1 -1 -1 6208316605742 -1 53024886805 -1
result:
wrong answer 1st lines differ - expected: '163825824623411', found: '-1'
Test #14:
score: 0
Wrong Answer
time: 48ms
memory: 1124kb
input:
10 411060288 247 193494425 14 162692451 151 282497312 400 796796095 370 100991720 365 560074247 197 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer 1st lines differ - expected: '236839515269254', found: '-1'
Test #15:
score: 5
Accepted
time: 48ms
memory: 1156kb
input:
10 733526255 46680 232614188 25143 740109721 35101 664765419 65813 926232187 19192 248710599 18813 7...
output:
483424517485 2802928408299 10384204202775 5885601631818 1006825631184 685064834622 84805986649153 16...
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 48ms
memory: 1160kb
input:
10 40397805 9224 854461643 50758 463970290 6807 993317097 75888 496579182 67022 428873070 56575 8340...
output:
2384944063443 7726610589534 4885508641726 3458814687913 6103014773068 4510437960348 1113055112999 75...
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 44ms
memory: 1160kb
input:
10 677231818 45638 135553472 57886 334073954 74682 504512612 32658 528899984 14506 658263816 15374 1...
output:
11785305009104 2638771729442 10698353380506 2437204760 4250858104139 509454788989 262157984498 29617...
result:
ok 10 lines
Test #18:
score: 0
Wrong Answer
time: 48ms
memory: 1160kb
input:
10 591761203 22205 53945697 65976 829627579 78277 112598137 27980 144133461 55044 668263637 96424 30...
output:
408922312723 2908118947003 291404913561 3375292130336 3950791693215 8266974861556 111818018746 37437...
result:
wrong answer 10th lines differ - expected: '78630557280367', found: '-1'
Test #19:
score: 5
Accepted
time: 48ms
memory: 1156kb
input:
10 798158737 58985 625637387 56023 950567276 86709 613154552 23440 2676550 96868 636525260 84971 205...
output:
1279542967427 10861221748856 23554542206 72816999418459 1962460002814 2579800768635 4144098383788 11...
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 48ms
memory: 1160kb
input:
10 76769987 47758 832950079 87350 226318103 39942 857729326 28604 700759579 85249 4088534 87174 7300...
output:
845532903085 5640616119076 21726121550 63299765465801 14907384186955 9900452209294 243405639246 5444...
result:
ok 10 lines