QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#877846 | #8321. 季风 | cyc001 | 0 | 0ms | 0kb | C++23 | 2.9kb | 2025-02-01 11:06:20 | 2025-02-01 11:06:20 |
Judging History
answer
#include<bits/stdc++.h>
#define cir(i,a,b) for(int i=a;i<b;++i)
using namespace std;
ifstream fcin("wind.in");
ofstream fcout("wind.out");
class fileio{
public:
~fileio(){
fcin.close();fcout.close();
}
} use_fileio;
using lint=long long;
using qint=__int128_t;
static constexpr auto _infl=(lint)(1e18l);
auto&operator>>(istream&is,qint&x){
string s;is>>s;x=0;auto sgn=1;
if(s[0]=='-') sgn=-sgn,s.erase(s.begin());
for(auto&w:s) (x*=10)+=(w-'0');
x*=sgn;
return is;
}
constexpr auto abs(qint x){return x<0?-x:x;}
int main(){
ios::sync_with_stdio(false),fcin.tie(nullptr);
int T;fcin>>T;
while(T--) [&]{
int n;qint k,x,y;fcin>>n>>k>>x>>y;
vector<qint> a(n),b(n);
cir(i,0,n) fcin>>a[i]>>b[i];
// |\sum a - X| + |\sum b - Y| \le mK
// X + Y - \sum (a + b + K) \le 0
// X - Y - \sum (a - b + K) \le 0
// - X + Y - \sum (- a + b + K) \le 0
// - X - Y - \sum (- a - b + K) \le 0
auto chkl=[&](qint w,qint v){
if(w<0) return 0ll;
return v<1?_infl+1:(lint)((w+v-1)/v);
};
auto chkr=[&](qint w,qint v){
if(v>0) return _infl;
if(w>0) return -1ll;
if(!v) return _infl;
return (lint)((-w)/(-v));
};
auto check=[&](qint w,qint v){
// w - v * x \le 0
return make_pair(chkl(w,v),chkr(w,v));
};
auto cap=[&](auto a,auto b){return make_pair(max(a.first,b.first),min(a.second,b.second));};
auto ans=_infl;
const auto suma=accumulate(a.begin(),a.end(),(qint)(0));
const auto sumb=accumulate(b.begin(),b.end(),(qint)(0));
auto vaild=[&](const auto cx,const auto cy,const auto w){
if(!k) return !(abs(cx-x)+abs(cy-y));
return (abs(cx-x)+abs(cy-y)+k-1)/k<w+1;
};
auto checkw=[&](const auto c){
auto prea=(qint)(0),preb=(qint)(0);
cir(i,0,n) if(vaild(suma*c+prea,sumb*c+preb,(lint)(c)*n+i)){
ans=min(ans,(lint)(c)*n+i);
return true;
}else{
prea+=a[i];preb+=b[i];
}
return false;
};
checkw(0);
auto prea=(qint)(0),preb=(qint)(0);
cir(i,0,n){
const auto result=cap(
cap(
check(x+y-(prea+preb+i*k),suma+sumb+n*k),
check(x-y-(prea-preb+i*k),suma-sumb+n*k)
),
cap(
check(-x+y-(-prea+preb+i*k),-suma+sumb+n*k),
check(-x-y-(-prea-preb+i*k),-suma-sumb+n*k)
)
);
prea+=a[i];preb+=b[i];
if(result.first<result.second+1) ans=min(ans,result.first*n+i);
}
fcout<<(ans==_infl?-1:ans)<<'\n';
}();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Dangerous Syscalls
input:
300 1 32286 -66773299 39159226 2655 14568 1 9900506 22484330 26135209 -33930 -9866575 1 669210 -40846340 -58419438 -529764 8866 1 74 -74443560 -78969527 -14 -37 1 473964 -91643319 -21680398 106817 243107 1 8543824 31629618 -37823687 1090776 4153469 1 16 -8109 -8410 -16 0 1 794120 -60084819 -21436725...
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
300 1 0 14658671 -17744707 -19 23 1 0 -43777875 2899010 1318511 -388002 1 0 -39267054 -13736220 -19633527 -6868110 1 0 51104805 90132261 1473 -925 1 0 -30105792 20070528 48 -32 1 0 -73521410 -3106528 7939241 3095051 1 0 1934605 -4643052 -5 12 1 0 10981610 -30724102 5490805 -15362051 1 0 -8877616 887...
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
300 1 342739 0 84733186 0 0 1 1 -71236915 69825956 0 0 1 1 96944547 67493888 0 0 1 101010 10720443 27403069 0 0 1 0 -47050862 27820930 0 0 1 299851 -32954036 24041633 0 0 1 22039 16175909 -32970576 0 0 1 54 -92637795 -64306686 0 0 1 65 -42213950 -76922091 0 0 1 48846 0 20220443 0 0 1 4641 0 0 0 0 1 ...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
300 1 491 19238896 24359756 2923207 -8745945 1 28452 -33430186 -3983771 18956 9495 1 1198593 -53848855 -4734461 93056 1105536 1 676 2931070 -9330910 52 -67 1 10 55228984 8970 -5 0 1 765812 2781176 64328480 -208 -223 1 0 -18744011 -35145767 -24 -45 1 251234 23812841 -10427626 -6279 -6797 1 996 -44886...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
686 4 123 61343816 -81149292 43 62 -26 -93 68 31 -103 0 2 41 5546 -92990467 -40 0 -25 0 6 835927 -25588646 -89091109 644485 191442 677934 157993 398739 437187 762871 73056 776002 59925 553067 282859 2 542128 21060442 -2011 -23932 0 -25454 0 3 1 44172958 49903094 -1 0 -1 0 0 0 1 4491 18010618 -313236...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
684 7 0 -4659965 65259689 -4659965 -99999977 0 0 0 0 0 0 4659965 99999979 0 0 0 0 1 0 18167938 67528693 18167938 67528693 7 0 -98200220 34188772 -98200220 34188772 -68294507 12668575 -28670964 -87244428 -98971553 90836074 74941179 92402443 10378449 63151034 -11200823 12733866 3 0 -80260647 -12683275...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
667 6 22320 -47869922 -94574425 -35667 -912623 452472 -751486 42399 685787 -602148 221313 389986 58340 504503 896866 3 568 40479510 -78492210 -218 -454519 249230 -310323 -501776 -456425 4 96 -34634275 -41782650 450066 2475397 -1983097 1089604 -2006742 1395784 394497 -1700181 2 586988 87270830 324220...
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
5026 7 1536 96224177 3215062 -431 -1063 -930 207 392 -343 -151 -351 190 240 708 -222 1084 -118 2 2007 4875 8961 0 -1006 1282 725 3 74 6255 36271857 2 0 2 0 39 0 4 299644 51336139 54387095 -223835 -75808 -50044 -249599 -36180 -263463 -257793 -41851 5 87337 46515166 83800720 -45698 -41639 -38633 -4870...
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
5021 4 0 -12747354 40715188 8473127 -24739598 -4402460 47229129 -63791499 59230380 38500351 -16265125 1 0 13024199 16963243 -2413 -27747 4 0 85556443 48034225 66661568 99999993 18894875 99999991 -19570239 -99999994 -65986204 -99999993 1 0 -64373357 -92003118 3 0 3 0 -57596351 -55622531 -97485 -45744...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
50122 5 25999922 8405 55768791 -1508111 -18663017 17765724 618297 -4046292 -11237396 -7742552 -12278384 6308331 3503946 2 204 -78318892 -78082051 582 -858 -620 -1217 2 33912059 -80164190 40071329 -4 -3 4 -3 1 281690 -6253970 14352972 -4363 328 5 11522477 13398456 -59393899 -173 -366 -221 -193 -484 1...