QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679905 | #6812. Draw a triangle | lllei# | AC ✓ | 32ms | 3708kb | C++20 | 1.5kb | 2024-10-26 19:10:50 | 2024-10-26 19:10:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template<typename T>
T exgcd(T a, T b, T &x, T &y){
if (!b){
x = 1, y = 0;
return a;
}
T r = exgcd(b, a % b, y, x);
y -= a / b * x;
return r;
}
// a * x = b (mod m) or b / a (mod m)
array<LL, 2> modequ(LL a, LL b, LL m){
LL x, y;
LL g = exgcd(a, m, x, y);
if (b % g) return {-1, -1};
m /= g, a /= g, b /= g;
x = 1LL * x * b % m;
if (x < 0) x += m;
return {x, m};
}
int sgn(LL x) {
if (x > 0) {
return 1;
} else if (x < 0) {
return -1;
} else {
return 0;
}
}
void solve() {
LL x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
cout << x1 + 1 << ' ' << y1 << '\n';
return;
}
if (y1 == y2) {
cout << x1 << ' ' << y1 + 1 << '\n';
return;
}
LL dx = abs(x2 - x1), dy = abs(y2 - y1);
if (dx == dy) {
cout << x1 + 1 << ' ' << y1 << '\n';
return;
}
LL g = gcd(dx, dy);
dx /= g, dy /= g;
if (dx == 1) {
cout << x1 << ' ' << y1 + 1 << '\n';
return;
}
auto [x, m] = modequ(dy, 1LL, dx);
LL t = (y1 + x * sgn(x2 - x1) * (y2 - y1) / (x2 - x1));
cout << x1 + sgn(x2 - x1) * x << ' ' << t << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 1 0 1 4 0 1 0 9 0 0 2 2
output:
2 0 1 1 1 0
result:
ok T=3 (3 test cases)
Test #2:
score: 0
Accepted
time: 21ms
memory: 3572kb
input:
50000 66620473 -33485015 66620223 -33485265 43307886 98029243 43307636 98028994 -88895230 -3180782 -88895480 -3181030 -90319745 20018595 -90319995 20018348 -56783257 84789686 -56783507 84789440 -81798038 90629147 -81798288 90628902 98942945 -939146 98942695 -939390 -42532151 -57203475 -42532401 -572...
output:
66620474 -33485015 43307637 98028995 -88895354 -3180905 -90319828 20018513 -56783319 84789625 -81798087 90629099 98942862 -939227 -42532258 -57203579 53500176 -30665635 27114943 46989027 -2657436 26865440 40614023 17923268 -47650008 96037612 92954122 -64535082 86508758 -51415267 -82017733 17392543 7...
result:
ok T=50000 (50000 test cases)
Test #3:
score: 0
Accepted
time: 21ms
memory: 3640kb
input:
50000 57869123 -31462316 57868973 -31462566 -22048649 -27017563 -22048799 -27017812 80245618 -10283113 80245468 -10283361 -96265076 -90677482 -96265226 -90677729 22392625 4659329 22392475 4659083 -85852423 89101455 -85852573 89101210 -59733414 34194238 -59733564 34193994 -64971121 90615380 -64971271...
output:
57869121 -31462319 -22048696 -27017641 80245569 -10283194 -96265209 -90677701 22392614 4659311 -85852442 89101424 -59733422 34194225 -64971142 90615346 52018823 -19951819 51552770 -19786088 -23565168 -10551159 -25829991 37587810 -8799479 83624983 9753834 -53464673 30266687 -36069277 -59557800 384870...
result:
ok T=50000 (50000 test cases)
Test #4:
score: 0
Accepted
time: 15ms
memory: 3620kb
input:
50000 -4816480 -62927672 -4816530 -62927922 38837454 51846136 38837404 51845887 81700780 -17769080 81700730 -17769328 -2355821 -67457821 -2355871 -67458068 38958908 -79915945 38958858 -79916191 -22432180 -56740626 -22432230 -56740871 -30176805 95059932 -30176855 95059688 -42037280 55545124 -42037330...
output:
-4816480 -62927671 38837405 51845892 81700756 -17769199 -2355854 -67457984 38958896 -79916004 -22432189 -56740670 -30176813 95059893 -42037287 55545090 -42817839 -74016050 41116115 -55536948 74807765 67612802 -22054538 93125785 -1291945 -7415405 90952813 97296402 -29863887 79534382 9616870 -75170351...
result:
ok T=50000 (50000 test cases)
Test #5:
score: 0
Accepted
time: 20ms
memory: 3572kb
input:
50000 47565990 63314613 47566040 63314364 -6671692 -8431430 -6671642 -8431678 -56437314 67409796 -56437264 67409549 -19754631 97449419 -19754581 97449173 22709358 -65094552 22709408 -65094797 -9253477 92786383 -9253427 92786139 60264780 -99332277 60264830 -99332520 42759753 13104536 42759803 1310429...
output:
47566039 63314369 -6671668 -8431549 -56437281 67409633 -19754619 97449360 22709367 -65094596 -9253469 92786344 60264787 -99332311 42759759 13104507 -59911965 -29129398 77502716 67904171 -25769456 -16449527 61092642 -55411719 -53400129 -61158203 -25069313 88946421 -21853231 -11367357 -27295587 -65633...
result:
ok T=50000 (50000 test cases)
Test #6:
score: 0
Accepted
time: 21ms
memory: 3536kb
input:
49999 86077178 -33791178 86077328 -33791427 70274103 92949056 70274253 92948808 -98644776 -36717042 -98644626 -36717289 -58640982 -37021140 -58640832 -37021386 47389280 88658595 47389430 88658350 41133739 -18298063 41133889 -18298307 16742668 91602345 16742818 91602102 64705012 76220813 64705162 762...
output:
86077225 -33791256 70274152 92948975 -98644643 -36717261 -58640971 -37021158 47389299 88658564 41133747 -18298076 16742689 91602311 64705043 76220763 11696216 -41244713 -85775743 -61100845 67944194 10706541 86636067 -72743053 -80900531 -4929107 -15258482 -90513091 -57595898 -13548473 34137615 875626...
result:
ok T=49999 (49999 test cases)
Test #7:
score: 0
Accepted
time: 31ms
memory: 3604kb
input:
50000 -370035325 -480207325 197507381 563102266 -447653163 -13791299 712913474 279375990 -164085901 515918101 -746049282 520422889 -351774171 -526736185 986786085 570845376 -139080671 -314883129 -653624395 -401153986 371330972 295281720 716532063 406617905 713639850 932579042 -697994312 -837319029 -...
output:
128241904 435772048 -339517866 13524437 -551175648 518914436 -177742226 -384034911 -588484916 -390232390 667134925 390686064 508877689 675849527 -385131636 -550186425 895639177 -50713300 829632713 41469719 -510154799 533361187 151183776 -349152331 -197515884 -162638542 190196029 -306399136 499898401...
result:
ok T=50000 (50000 test cases)
Test #8:
score: 0
Accepted
time: 31ms
memory: 3708kb
input:
50000 38026624 -878076357 -552920439 -350794846 -412973070 -567080550 -956686128 247707367 293749788 -47698118 949332510 803776854 -37716684 -75717498 -384102742 -111390691 252319124 -407086186 -298274705 553686185 195690205 -960978213 693203670 751867944 -44794927 146815392 497184663 -657312706 244...
output:
-513265195 -386177841 -774548479 -25237256 440533870 142945973 -204381765 -92881802 45010727 -45338252 449121328 -88462079 58837972 -6943398 676940382 129159878 -458908877 449350296 101985857 -288291927 795202238 390932503 -727650943 -623255007 521312587 -146814508 -941951771 887636989 576187897 253...
result:
ok T=50000 (50000 test cases)
Test #9:
score: 0
Accepted
time: 32ms
memory: 3620kb
input:
50000 25273482 -271356160 203127555 -184489837 -289853919 200578127 408716355 587561320 440221844 -73945468 -375731352 -330991327 452223216 -181778460 -163936693 -539981093 538901710 569206009 766705704 719561034 -491626613 -671982599 527872032 -29445214 -63710429 421304993 -622588079 487115265 -476...
output:
48376926 -260072127 373105214 567834009 -47815735 -227689628 160750960 -351224943 759255423 714643705 -390558911 -608284842 -334955170 453245240 332089394 -57957435 75179887 292207306 485659964 -898073458 -467632245 -68664120 -192970889 -184358428 811818734 510750874 -808675780 105148981 -468827463 ...
result:
ok T=50000 (50000 test cases)
Test #10:
score: 0
Accepted
time: 31ms
memory: 3708kb
input:
50000 -35259334 -701474112 311852823 -331381965 572375773 934385697 63613329 -82033074 963625204 106699315 855551972 -604089908 -239314379 -375979612 122091992 -380831468 -884798360 -827592392 -450362161 940295667 -209340085 -40153027 -361999245 620160834 877357984 882062152 315363830 559500049 -414...
output:
100685842 -556528909 380054934 550162150 943281565 -27099213 -165227375 -376974225 -800664744 -485220335 -226541746 34251255 670131061 763122210 -172382142 -780520239 -112006078 -310805642 327568478 -496145635 158607620 -106166975 507194200 -178696250 782929007 229259539 -300136497 371073894 -380937...
result:
ok T=50000 (50000 test cases)
Test #11:
score: 0
Accepted
time: 31ms
memory: 3584kb
input:
50000 -3663853 -177781773 173552690 705221364 -960654525 -342974336 754897176 504780355 494495391 471831124 -843629424 476927366 348629524 -909106658 627892786 725953059 -523367521 102557145 502351897 -236989097 -299381834 260178935 -743399500 51860789 335298045 -183924414 720046790 -631868047 17038...
output:
19026253 -64725540 -389429069 -60698343 -340089082 475009635 380075307 -724994603 -59721163 -50924768 -487823724 171768342 451824482 -319590290 225597250 638958134 712087259 701845650 -681674591 944463724 290384228 37350965 -506797283 -656030854 359647619 811991396 386107475 682303693 155763204 -350...
result:
ok T=50000 (50000 test cases)
Test #12:
score: 0
Accepted
time: 31ms
memory: 3552kb
input:
50000 87994422 -469168315 -282663695 303996144 -153451281 -314512069 -168298547 948863838 -293926308 -170703744 789655924 -859296264 930120677 671761062 934908485 938519828 -62509863 497504980 258338790 286307134 166058928 434063507 329625200 250123198 170938223 -712363899 -476975593 -946264304 -351...
output:
-121431777 -32321295 -155918744 -104551979 -246225164 -201016765 930185004 675345122 -28528191 475136627 174388333 424696580 34064370 -761776103 145003180 450092208 632458503 218622176 589289787 -794758090 -349004180 202285536 -398980187 -896434686 -820412666 469700568 -25069657 -652082394 -74925058...
result:
ok T=50000 (50000 test cases)
Test #13:
score: 0
Accepted
time: 28ms
memory: 3636kb
input:
50000 75983688 322870644 646834996 801552184 519110129 -976686263 -819619684 -828820558 570394281 246976850 519558688 367109464 621047758 927882674 148954683 991061997 88827271 210457738 -857995083 -457237784 112341241 -890456500 223281366 792319429 -102888330 389111504 665082474 -58495814 -70874021...
output:
170258232 401923601 440033434 -967952065 541337827 315641885 401290321 957292396 -6126948 143496384 215117785 668491575 123466535 257181887 -639864485 451261017 -135764425 291300188 191111104 -617353933 181478635 -629865714 885484900 -568892032 -378779081 -398140810 -381891470 715514316 487805210 -1...
result:
ok T=50000 (50000 test cases)
Test #14:
score: 0
Accepted
time: 31ms
memory: 3560kb
input:
50000 -805634427 81825426 509577423 -396279363 -267738158 -532191054 179134956 521282089 893958536 -637235181 -336434702 -730924494 209380302 -981860939 -104731724 351669816 693569118 -145872073 215960733 -538852028 278991643 856418697 472101398 561793859 773440456 -666647571 296326173 621945233 -88...
output:
-573784550 -2456461 121858151 386255895 570785181 -661843484 113918677 -576588290 680980255 -156230289 356021860 738894778 630397772 -280317126 -884801087 -292336810 201999286 376461531 -42650392 -819606648 -116369714 391977619 -853534856 -639377749 188506504 -801148575 -479512623 295419842 15775306...
result:
ok T=50000 (50000 test cases)
Test #15:
score: 0
Accepted
time: 30ms
memory: 3684kb
input:
50000 725941728 -610067425 488068370 -504082729 476613211 -620476119 476920048 -111480150 245593358 -660602217 471175896 888995542 280795134 -289504448 -967836825 -760152213 -486471673 -224674228 934607251 -450295850 -694176146 751372343 -891227475 -364721717 830792306 -773436907 523127672 424703167...
output:
615811205 -560998668 476651067 -557678766 373304035 216682792 55164368 -374551619 -394817988 -239225885 -787773771 221237612 787056637 -603116851 889135885 -151484486 -419727851 934218717 712961166 700340428 -28604299 -665762004 -175178321 -579921966 -585521082 -707478112 556197552 -406518574 429779...
result:
ok T=50000 (50000 test cases)
Test #16:
score: 0
Accepted
time: 31ms
memory: 3568kb
input:
50000 104556371 -685734071 -731906759 -604652123 396789892 -935692027 -576229790 -207110549 -578953998 541207525 -516985486 542399334 -878495739 -596088045 119106374 -251106029 -363926466 866046756 158763085 -478051966 599120280 -275757280 -282204734 820871313 -588932159 -793669810 680396515 -770178...
output:
-134831593 -662529172 286211073 -852892387 -566428685 541448418 -34807519 -304331182 -244940516 560073807 -22473331 497688743 -55812108 -783803510 25503449 -386709974 500052696 113681508 940689483 -95344844 -8085631 193145226 393919821 63125575 -684499497 -763114019 536075966 489239151 -25441007 590...
result:
ok T=50000 (50000 test cases)
Test #17:
score: 0
Accepted
time: 31ms
memory: 3612kb
input:
50000 -913971105 -802525545 -62443082 646851152 582546207 -691701688 -263954188 574883995 -88743623 992720648 272194515 -762942323 -840733072 -332078482 -575663610 244914353 440623464 752008161 -470122956 920792991 -757686511 643488102 708042881 -627877550 185019277 307661180 -692173668 848015507 75...
output:
-742587546 -510815431 497552195 -564528447 31443672 408109710 -713707125 -55573370 436084361 752849374 -445801934 372961127 -389798626 661751284 74747747 423549156 -814436809 263552374 235980749 -417818925 337318438 557490189 -374614367 -414957501 353137138 -23187480 361737954 -369236565 720981260 6...
result:
ok T=50000 (50000 test cases)
Test #18:
score: 0
Accepted
time: 31ms
memory: 3708kb
input:
50000 185492989 3104323 -418943377 -567314244 -716676172 339998445 -419312863 -525301490 -610060612 777476899 -418834808 -571211717 39944725 -455257290 -829398804 201165129 -466129455 -464184034 735772464 931681523 -466599024 -740319024 563884212 3148693 -505528308 -808674422 -6340257 -358696593 -85...
output:
-295461280 -450781744 -454786052 -422077766 -605936596 748390796 -123156079 -332103415 -222976449 -181790853 -230813939 -570206020 -80882026 -425889995 599325617 104341415 237531675 -255850344 -301367720 -579396028 121558901 -162192911 -786938625 -100068032 -123711039 729736275 154718475 -215574939 ...
result:
ok T=50000 (50000 test cases)
Test #19:
score: 0
Accepted
time: 31ms
memory: 3532kb
input:
50000 -474636599 -626920443 712875021 -348747799 -342048305 37518714 -249508888 482083100 -410519206 -225607946 27339059 407774804 -345676873 559668812 88853181 453485769 999517103 522173138 135806165 -45307125 -285232985 -711392209 656546715 686223071 -736883128 630709030 260930401 -627544060 34322...
output:
-336085368 -594465045 -283566240 318469731 -407082935 -220637217 -4788996 476368447 619740636 272650248 -261023256 -675464606 -106487404 -164226441 148661394 -243966047 -49694672 -333729644 -807975218 -806255815 152518387 -144927251 -111273100 54019454 651973143 925118567 -296788040 -773429408 10534...
result:
ok T=50000 (50000 test cases)
Test #20:
score: 0
Accepted
time: 31ms
memory: 3620kb
input:
50000 626800159 776374206 -41956635 417375236 -536924579 414783144 847473468 181350188 103033152 456387414 906877647 -901512211 784792043 -200142589 761424984 571942095 -319313812 593906734 -329157602 -688825321 790537948 -567376329 -989657217 -909342264 82546755 272767210 -982948739 -187576605 3536...
output:
357605996 631866624 447870837 248729959 167184167 348019888 775059674 121430316 -319341225 590334580 722151227 -580513051 -405628990 61852489 280245312 780380799 737047778 -647053479 -532398178 424691878 -579892777 -628260594 -739378607 -176021572 -468728539 -339995636 163974604 204414487 250985977 ...
result:
ok T=50000 (50000 test cases)
Test #21:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000
output:
-999999999 -1000000000 -1000000000 -999999999 -999999999 -1000000000
result:
ok T=3 (3 test cases)