QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121416#1146. Railsomethingnew#8 3ms4356kbC++206.2kb2023-07-08 04:20:522024-07-04 00:30:06

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:30:06]
  • 评测
  • 测评结果:8
  • 用时:3ms
  • 内存:4356kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 04:20:52]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include <unistd.h>
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
/* This is sample grader for the contestant getDistance*/
#include "rail.h"
int getdst(int frst, int x, int fromleft, set<pair<int, int>> &lftcnt, set<pair<int, int>> &rgtcnt) {
    if (fromleft) {
        if (frst <= x) {
            return x - frst;
        } else {
            auto it1 = lftcnt.lower_bound({frst, 0});
            if (it1 == lftcnt.end())
                return -1;
            pair<int, int> pos = *it1;
            int res = pos.first - frst;
            auto it2 = rgtcnt.lower_bound({x-1, 100001});
            if (it2 == rgtcnt.begin())
                return -1;
            pair<int, int> pos2 = *(--it2);
            res += pos.first - pos2.first;
            res += x - pos2.first;
            return res;
        }
    } else {
        auto it1 = lftcnt.lower_bound({x+1, 0});
        if (it1 == lftcnt.end())
            return -1;
        pair<int, int> pos = *it1;
        int res = pos.first - frst + pos.first - x;
        return res;
    }
}
void findLocation(int n, int first, int location[], int stype[]) {
    location[0] = first;
    stype[0] = 1;
    vector<pair<int, int>> resba;
    for (int i = 1; i < n; ++i) {
        resba.push_back({getDistance(0, i), i});
    }
    sort(all(resba));
    set<pair<int, int>> lftcnt, rgtcnt;
    for (auto i : resba) {
        if (lftcnt.empty()) {
            lftcnt.insert({i.first + first, i.second});
            location[i.second] = i.first + first;
            stype[i.second] = 2;
        } else {
           // cout << i.first << ' ' << i.second << '\n';
          //  cout << -v2 + lftcnt.rbegin()->first << '\n';
            if (!rgtcnt.empty()) {
                int v2 = getDistance(rgtcnt.begin()->second, i.second);
                //  cout << v2 + rgtcnt.begin()->first << '\n';
                if (getdst(first, v2 + rgtcnt.begin()->first, 1, lftcnt, rgtcnt) == i.first) {
                    // cout << "Yes\n";
                    lftcnt.insert({v2 + rgtcnt.begin()->first, i.second});
                    location[i.second] = v2 + rgtcnt.begin()->first;
                    stype[i.second] = 2;
                    continue;
                }
                //cout << "No\n";
            }
            int v2 = getDistance(lftcnt.rbegin()->second, i.second);
            if (getdst(first, -v2 + lftcnt.rbegin()->first, 0, lftcnt, rgtcnt) == i.first) {
          //      cout << "Yes\n";
                rgtcnt.insert({-v2 + lftcnt.rbegin()->first, i.second});
                location[i.second] = -v2 + lftcnt.rbegin()->first;
                stype[i.second] = 1;
                continue;
            }
          //  cout << "No\n";
            lftcnt.insert({i.first + first, i.second});
            location[i.second] = i.first + first;
            stype[i.second] = 2;
        }
    }
}
/*
typedef struct Station {
    int index;
    int type;
    int location;
    int L,R;
}STATION;
long long cnt;
static int S,SUBTASK;
static STATION stations[10004];

int cmp_fun_1(const void *a,const void *b)
{
    STATION c,d;
    c = *(STATION*)(a);
    d = *(STATION*)(b);
    return c.location < d.location ? -1 : 1;
}

int cmp_fun_2(const void *a,const void *b)
{
    STATION c,d;
    c = *(STATION*)(a);
    d = *(STATION*)(b);
    return c.index < d.index ? -1 : 1;
}

void now_I_want_to_getLR(){
    int now = stations[S-1].index,i;
    for(i=S-2;i>=0;i--){
        stations[i].R = now;
        if(stations[i].type==2)	now = stations[i].index;
    }
    now = stations[0].index;
    for(i=1;i<S;i++){
        stations[i].L = now;
        if(stations[i].type==1)	now = stations[i].index;
    }
}

int getDistance(int x,int y)
{
    cnt++;
    if(x==y)	return 0;
    if(x<0 || x>=S || y<0 || y>=S)    return -1;
    if(stations[x].location > stations[y].location){
        int tmp = x;
        x = y;
        y = tmp;
    }
    int ret = 0;
    if(stations[x].type==1 && stations[y].type==1){
        ret = stations[stations[y].R].location-stations[x].location+stations[stations[y].R].location-stations[y].location;
    }else if(stations[x].type==1 && stations[y].type==2){
        ret = stations[y].location-stations[x].location;
    }else if(stations[x].type==2 && stations[y].type==2){
        ret = stations[x].location-stations[stations[x].L].location+stations[y].location-stations[stations[x].L].location;
    }else if(stations[x].type==2 && stations[y].type==1){
        ret = stations[x].location-stations[stations[x].L].location+stations[stations[y].R].location
              -stations[stations[x].L].location+stations[stations[y].R].location-stations[y].location;
    }
    return ret;
}


void getInput()
{
    int g;
    g = scanf("%d",&SUBTASK);
    g = scanf("%d",&S);
    int s;
    for (s = 0; s < S; s++) {
        int type, location;
        g = scanf(" %d %d",&type,&location);
        stations[s].index = s;
        stations[s].location = location;
        stations[s].type = type;
        stations[s].L = -1;
        stations[s].R = -1;
    }
    qsort(stations, S, sizeof(STATION), cmp_fun_1);
    now_I_want_to_getLR();
    qsort(stations, S, sizeof(STATION), cmp_fun_2);
}

int serverGetStationNumber()
{
    return S;
}

int serverGetSubtaskNumber()
{
    return SUBTASK;
}

int serverGetFirstStationLocation()
{
    return stations[0].location;
}

int main()
{
    int i;
    getInput();
    cnt = 0;

    int location[10005];
    int type[10005];
    int ok = 1;
    findLocation(S, serverGetFirstStationLocation(),location, type);
    if(SUBTASK==3 && cnt>S*(S-1))	ok = 0;
    if(SUBTASK==4 && cnt>3*(S-1))	ok = 0;


    for (i = 0; i < S; i++)
        if(type[i]!=stations[i].type || location[i]!=stations[i].location)
            ok = 0;
    if(ok==0)	printf("Incorrect");
    else	printf("Correct");
    return 0;
}
*/

詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 1ms
memory: 3736kb

input:

1
100
1 11
2 794
2 775
2 347
2 737
2 864
2 584
2 555
2 361
2 429
2 892
2 302
2 483
2 217
2 39
2 566
2 435
2 448
2 304
2 466
2 386
2 780
2 164
2 918
2 601
2 867
2 929
2 341
2 636
2 556
2 954
2 430
2 683
2 301
2 519
2 547
2 237
2 426
2 908
2 667
2 670
2 210
2 502
2 887
2 420
2 675
2 401
2 724
2 493
2 ...

output:

Correct

result:

ok 

Test #2:

score: 8
Accepted
time: 1ms
memory: 3848kb

input:

1
100
1 13
2 768
2 165
2 101
2 185
2 678
2 145
2 865
2 650
2 769
2 985
2 756
2 236
2 973
2 688
2 522
2 654
2 316
2 598
2 901
2 274
2 547
2 744
2 511
2 684
2 331
2 822
2 757
2 198
2 85
2 526
2 363
2 186
2 711
2 393
2 683
2 928
2 43
2 805
2 914
2 152
2 239
2 840
2 916
2 893
2 509
2 514
2 561
2 410
2 7...

output:

Correct

result:

ok 

Test #3:

score: 8
Accepted
time: 1ms
memory: 3740kb

input:

1
100
1 21
2 40
2 217
2 337
2 711
2 392
2 260
2 838
2 625
2 839
2 378
2 468
2 338
2 105
2 663
2 79
2 993
2 811
2 398
2 694
2 742
2 937
2 281
2 131
2 733
2 710
2 520
2 128
2 381
2 912
2 345
2 718
2 623
2 90
2 330
2 983
2 307
2 168
2 608
2 147
2 898
2 428
2 837
2 92
2 268
2 349
2 255
2 667
2 43
2 270
...

output:

Correct

result:

ok 

Test #4:

score: 8
Accepted
time: 1ms
memory: 3788kb

input:

1
100
1 30
2 512
2 723
2 790
2 546
2 811
2 767
2 427
2 761
2 489
2 938
2 287
2 195
2 145
2 231
2 87
2 62
2 691
2 671
2 583
2 268
2 522
2 395
2 632
2 500
2 873
2 863
2 478
2 447
2 904
2 809
2 311
2 627
2 951
2 857
2 718
2 636
2 552
2 560
2 574
2 191
2 755
2 71
2 774
2 194
2 134
2 466
2 866
2 69
2 86
...

output:

Correct

result:

ok 

Test #5:

score: 8
Accepted
time: 1ms
memory: 3864kb

input:

1
100
1 38
2 657
2 545
2 832
2 707
2 992
2 829
2 423
2 985
2 162
2 897
2 335
2 744
2 756
2 352
2 238
2 268
2 677
2 824
2 960
2 733
2 496
2 411
2 63
2 675
2 223
2 745
2 193
2 85
2 885
2 202
2 630
2 717
2 910
2 622
2 898
2 685
2 413
2 934
2 647
2 157
2 690
2 999
2 395
2 310
2 425
2 134
2 323
2 510
2 9...

output:

Correct

result:

ok 

Test #6:

score: 8
Accepted
time: 0ms
memory: 3872kb

input:

1
100
1 12
2 669
2 901
2 133
2 896
2 738
2 776
2 44
2 134
2 154
2 29
2 638
2 937
2 874
2 235
2 397
2 779
2 709
2 588
2 701
2 324
2 965
2 865
2 251
2 710
2 715
2 689
2 249
2 174
2 551
2 270
2 427
2 684
2 518
2 165
2 812
2 914
2 298
2 68
2 899
2 936
2 357
2 773
2 524
2 755
2 552
2 233
2 343
2 605
2 90...

output:

Correct

result:

ok 

Test #7:

score: 8
Accepted
time: 1ms
memory: 3732kb

input:

1
100
1 47
2 198
2 904
2 942
2 714
2 510
2 431
2 594
2 690
2 75
2 449
2 786
2 920
2 277
2 731
2 742
2 136
2 760
2 633
2 224
2 637
2 927
2 959
2 222
2 657
2 474
2 611
2 401
2 307
2 759
2 952
2 563
2 701
2 666
2 425
2 484
2 613
2 115
2 505
2 688
2 564
2 292
2 609
2 194
2 375
2 703
2 330
2 336
2 555
2 ...

output:

Correct

result:

ok 

Test #8:

score: 8
Accepted
time: 0ms
memory: 3744kb

input:

1
100
1 7
2 631
2 253
2 535
2 16
2 311
2 891
2 250
2 698
2 843
2 525
2 43
2 740
2 429
2 610
2 643
2 276
2 529
2 243
2 174
2 229
2 537
2 288
2 685
2 459
2 823
2 878
2 72
2 759
2 663
2 573
2 366
2 294
2 179
2 842
2 144
2 265
2 541
2 340
2 791
2 936
2 432
2 572
2 898
2 75
2 201
2 427
2 670
2 375
2 8
2 ...

output:

Correct

result:

ok 

Test #9:

score: 8
Accepted
time: 1ms
memory: 3872kb

input:

1
100
1 34
2 445
2 537
2 285
2 903
2 312
2 975
2 250
2 885
2 125
2 818
2 557
2 560
2 525
2 400
2 227
2 577
2 50
2 340
2 748
2 390
2 370
2 508
2 663
2 150
2 144
2 923
2 741
2 746
2 909
2 100
2 191
2 446
2 385
2 759
2 713
2 696
2 996
2 838
2 515
2 353
2 747
2 75
2 879
2 499
2 654
2 456
2 550
2 994
2 9...

output:

Correct

result:

ok 

Test #10:

score: 8
Accepted
time: 0ms
memory: 3816kb

input:

1
100
1 31
2 325
2 179
2 190
2 113
2 350
2 720
2 553
2 712
2 465
2 524
2 657
2 671
2 665
2 390
2 348
2 620
2 901
2 342
2 116
2 649
2 724
2 473
2 789
2 618
2 890
2 449
2 334
2 669
2 232
2 363
2 346
2 763
2 554
2 459
2 114
2 626
2 178
2 91
2 889
2 180
2 100
2 912
2 197
2 843
2 260
2 170
2 96
2 954
2 2...

output:

Correct

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 3844kb

input:

2
100
1 7327
1 116
2 9993
1 2736
1 6502
1 4106
1 6326
2 8055
1 6767
1 388
2 7645
1 1780
1 6159
2 7738
1 3706
1 3476
2 9549
2 7564
1 2401
1 6353
2 8829
1 945
1 606
1 4664
2 9585
2 7499
1 6703
1 3229
1 1382
2 8286
1 6805
1 351
1 793
1 1641
1 3087
1 3647
1 2099
2 9414
1 1703
2 8866
2 9802
2 9348
1 6999...

output:

Incorrect

result:

wrong answer Token "Incorrect" doesn't correspond to pattern "Correct"

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 3ms
memory: 4356kb

input:

3
5000
1 763228
1 39310
2 962072
2 203549
1 85439
2 414565
2 78225
1 185073
2 174996
2 386604
1 662313
2 96651
1 271323
2 556033
1 788441
1 717148
1 404737
2 197742
2 760887
1 549658
2 713177
1 156708
1 858133
1 166177
1 809643
2 365041
1 73222
2 706708
2 296516
1 861386
1 782475
2 167675
1 100665
1...

output:

Incorrect

result:

wrong answer Token "Incorrect" doesn't correspond to pattern "Correct"

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 3ms
memory: 4216kb

input:

3
5000
1 763228
1 39310
2 962072
2 203549
1 85439
2 414565
2 78225
1 185073
2 174996
2 386604
1 662313
2 96651
1 271323
2 556033
1 788441
1 717148
1 404737
2 197742
2 760887
1 549658
2 713177
1 156708
1 858133
1 166177
1 809643
2 365041
1 73222
2 706708
2 296516
1 861386
1 782475
2 167675
1 100665
1...

output:

Incorrect

result:

wrong answer Token "Incorrect" doesn't correspond to pattern "Correct"