QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#840831#9903. 最短路径Justinshao0 625ms225488kbC++203.3kb2025-01-03 06:17:002025-01-03 06:17:10

Judging History

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

  • [2025-01-03 06:17:10]
  • 评测
  • 测评结果:0
  • 用时:625ms
  • 内存:225488kb
  • [2025-01-03 06:17:00]
  • 提交

answer

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rep(X, a, b) for(int X = a; X < b; ++X)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define ld long double
#define F first
#define S second

#ifdef LOCAL
#define ZTMYACANESOCUTE freopen("in.txt", "r", stdin);
#define debug(...) {cerr << #__VA_ARGS__ << " = "; dbg(__VA_ARGS__);}
#else
#define ZTMYACANESOCUTE ios_base::sync_with_stdio(0), cin.tie(0);
#define debug(...) 6;
#endif

void dbg() { cerr << '\n'; }
template<typename T, typename ...U>
void dbg(T t, U ...u) { cerr << t << ' '; dbg(u...); }

pii operator + (const pii &p1, const pii &p2) { return make_pair(p1.F + p2.F, p1.S + p2.S); }
pii operator - (const pii &p1, const pii &p2) { return make_pair(p1.F - p2.F, p1.S - p2.S); }
pll operator + (const pll &p1, const pll &p2) { return make_pair(p1.F + p2.F, p1.S + p2.S); }
pll operator - (const pll &p1, const pll &p2) { return make_pair(p1.F - p2.F, p1.S - p2.S); }

template<class T> bool chmin(T &a, T b) { return (b < a && (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b && (a = b, true)); }

#define lpos pos << 1
#define rpos pos << 1 | 1
 
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator << (ostream &os, const vector<A> &p) { for(const auto &a : p) os << a << " "; os << '\n'; return os; }
 
const int MAXN = 2e5 + 5, MOD = 998244353, IINF = 1e9 + 7, MOD2 = 1000000007;
const double eps = 1e-9;
const ll LINF = 1e18L + 5;
const int B = 320;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int get_rand(int l, int r){ return uniform_int_distribution<int>(l, r)(rng); }
 
ll fpow(ll x, ll exp, ll mod = LLONG_MAX){ ll res = 1; while(exp){ if(exp & 1) res = res * x % mod; x = x * x % mod; exp >>= 1;} return res; }

void solve() {
    int n, q; cin >> n >> q;
    vector a(n, vector<ll>(n));
    rep (i, 0, n) rep (j, 0, n) cin >> a[i][j];
    vector dis(n, vector<ll>(n, LINF));
    rep (i, 0, n) dis[i][i] = 0;
    vector<vector<vector<ll>>> ans(n);
    auto dfs = [&](auto self, int l, int r) -> void {
        if (l == r) {
            ans[l] = dis;
            return;
        }
        auto tmp = dis;
        int mid = l + r >> 1;
        rep (k, l, mid + 1) {
            rep (i, 0, n) rep (j, 0, n) {
                chmin(dis[i][j], a[i][k] + dis[k][j]);
                chmin(dis[j][i], dis[j][k] + a[k][i]);
            }
        }
        self(self, mid + 1, r);
        dis = tmp;
        rep (k, mid + 1, r + 1) {
            rep (i, 0, n) rep (j, 0, n) {
                chmin(dis[i][j], a[i][k] + dis[k][j]);
                chmin(dis[j][i], dis[j][k] + a[k][i]);
            }
        }
        self(self, l, mid);
    };
    dfs(dfs, 0, n - 1);
    while (q--) {
        int s, t, p; cin >> s >> t >> p;
        s--, t--, p--;
        cout << ans[p][s][t] << '\n';
    }
}
 
int main() {
    ZTMYACANESOCUTE;
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
}

詳細信息


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 12436kb

input:

100 100
0 7772271323914 22125803016911 3221373 4166251171807 748339783252 34065805188167 50811428832368 1367651438428 24197139580618 6663135541534 27879426632102 15365243414328 10780564011323 2018609024 397712557916 28396067120913 356407886112 44232262619414 162855983068 447276 67425790697675 173378...

output:

66780767
79190311
67551772
130323482
300451
27125870
46686875
15644900
24407847
350083
3262626
62095774
57808194
12215270
40627898
7237520
6386159
98423954
1914167
43636786
3219637
321631
69093837
7225976
192927668
14767230
11988315
10581553
56646822
20360990
4824788
14163111
28870611
80043098
24474...

result:

wrong answer 1st numbers differ - expected: '65676043', found: '66780767'

Test #2:

score: 0
Wrong Answer
time: 17ms
memory: 12436kb

input:

100 100
0 17578387256913 79089544497 431 594034211131 5170073338267 19361776466479 4427688105 11926603171157 45072603252 11943768005878 50148978000869 106737346550 27519538966959 37137900185801 3989886236022 15439195175968 19533214331980 4915912422439 66000188414990 29166748845681 354388844 66952055...

output:

13978568
3867786
2375637
10003505
8528453
9070391
88535251
155160685
9605982
23446758
28604060
846978
104399457
49068546
41851207
16402483
133962611
3212619
156591097
82520305
6646317
67502521
629338
6201248
47849525
3038580
28624371
4108070
28551934
23165961
208280929
28363700
34870499
128554113
26...

result:

wrong answer 1st numbers differ - expected: '270396', found: '13978568'

Test #3:

score: 0
Wrong Answer
time: 16ms
memory: 12392kb

input:

100 100
0 773801766444 3840925618 1343152952632 64307613436502 8683601469 45434524869106 81117353046 1987337565207 2858076509641 243425132692 1802644161264 25822170325295 6528483907 41283282749 3826491866697 22344866920790 96931641334570 5174664972951 1538931163479 47147864358837 51639382527727 9867...

output:

67636149
29601591
17052381
1156053
6664730
20523443
80169490
6897151
55882190
6971323
2253867
10830053
17349369
67899934
154162956
1616486
34207148
96369937
91338615
8427031
138009011
6173190
8961310
14462347
13132988
42432306
22740443
71463551
386763
91903478
30142460
24039018
3544960
16371892
8425...

result:

wrong answer 1st numbers differ - expected: '2561993', found: '67636149'

Test #4:

score: 0
Wrong Answer
time: 454ms
memory: 225348kb

input:

300 1000
0 1395254281321 81149967048674 808789341190 79819267873907 57367221292974 13013648824390 64258407230458 14605579839044 12975220495832 120220182607 39743014887008 3266138366431 119198662688 28545770063374 17260222479825 21107475181134 55682577272703 13633518098188 40028750178497 550275401200...

output:

8039954
1045728
621043
12765382
1822121
573641
255146
603345
1782234
949034
3525827
1981091
411938
68728
11081936
151048
2818450
2712822
4286022
5317634
2514482
11948209
833660
1732665
725993
2412277
2573410
726699
1918040
1155315
894014
6675570
6614407
1676389
610234
3843428
2008028
7164008
1747837...

result:

wrong answer 1st numbers differ - expected: '164487', found: '8039954'

Test #5:

score: 0
Wrong Answer
time: 486ms
memory: 225484kb

input:

300 1000
0 6409029058 18566975677517 1453118645319 19988064330 32639805173638 1639371569240 698806223545 185977936143 1082787768141 2239906104533 4403543180683 961039210337 4145037246 1858235 2692041139214 2307668378 1339668614 6253996882 17345652389482 1009665462517 17453151773298 3394297603587 135...

output:

1242044
3770430
1538432
1415030
1602458
6066085
1093312
15268375
1539957
3191959
3620853
1215778
241817
3639978
1846905
2478488
4284104
681291
1300132
12458822
439280
1164508
457228
336859
9125160
2758904
2953429
3446942
7932053
5167667
4000274
502070
10304174
2631905
3734873
2056220
861437
968037
5...

result:

wrong answer 1st numbers differ - expected: '172637', found: '1242044'

Test #6:

score: 0
Wrong Answer
time: 604ms
memory: 225416kb

input:

300 500000
0 87730664049 1603788381608 71952849510530 1142923985 24159738602021 92997246299231 64880292979225 50411033738604 54528465801 31135537246199 231468171471 419 236677264159 38114009155579 2508003778771 57570811058461 24329307886989 292160437 4902439019817 15740104936818 44927292337698 79204...

output:

994739
689144
2194500
9202973
509505
3785431
2612181
147959
1930875
3861072
526173
2296522
3192958
2589442
1130150
1605471
76735
2896937
2627384
3129292
1261921
6224105
1390503
2039746
833570
2705267
5379497
23397777
3971649
3112235
473606
218419
947764
128244
3204410
5725590
1268671
238437
1602777
...

result:

wrong answer 2nd numbers differ - expected: '54618', found: '689144'

Test #7:

score: 0
Wrong Answer
time: 625ms
memory: 225412kb

input:

300 500000
0 52626347413773 1707334632128 70009373655708 25860849031824 32110463708287 3869001849431 346520043666 34919901831451 18512922395 14200680384312 436214584213 79240628473151 14981957306825 1273864589622 475718847939 5308515658147 30868844002 272698735884 23608283030932 509189357147 1289077...

output:

3851024
1889904
1272132
4587627
8761134
775649
225623
435867
1136042
372235
1717414
1016341
2056284
455510
2280889
2806208
387773
136221
3035011
2581939
772869
3090685
1485325
5373705
369550
8368065
1094685
1881810
1262430
1881079
6064440
477791
2402422
1116762
164456
1842240
1590122
2094842
216644
...

result:

wrong answer 1st numbers differ - expected: '52439', found: '3851024'

Test #8:

score: 0
Wrong Answer
time: 609ms
memory: 225416kb

input:

300 500000
0 6330470680301 23874488164149 98626 4160170543478 91396404907 58736315444 12401313360570 14412917281027 38099628392841 282475659499 671873736937 772895099008 19153316198 7022869 27995285198114 11692649915256 7588637657572 823853943323 2206830727999 2151020585 915266887628 5916118204273 1...

output:

292668
1445939
1492423
1387164
1565360
1888228
1442696
1119881
4226989
234760
3132396
4772759
4803224
734835
1984598
11528828
3082074
968032
830796
3937540
4267635
4350771
875772
5343224
698605
3762390
3203145
631000
1954244
916070
2241582
2136825
708398
1464708
1491751
3803926
2092361
10399524
1181...

result:

wrong answer 1st numbers differ - expected: '54159', found: '292668'

Test #9:

score: 0
Wrong Answer
time: 603ms
memory: 225488kb

input:

300 500000
0 54720923847450 10903523785666 4358689132 83283776625462 8218771493732 35488829878660 3339439 6500864120913 61307902687569 53710291769435 19917041512 463251296446 6646718981507 2456241779832 481716427467 7469732375 21084043486 206425878 740838785326 11139961838828 136091417 806439547295 ...

output:

1452899
4449073
2143301
941598
334796
3528001
2589843
5615865
6029377
4734345
3327105
1837974
1889246
991952
361170
1477054
468845
3604118
2586022
1810913
6401450
1978594
14364810
4941949
1973521
2607567
71286
627459
473199
2666370
1286467
14771527
1792605
21912500
536834
2469902
2413322
2672737
184...

result:

wrong answer 1st numbers differ - expected: '177525', found: '1452899'

Test #10:

score: 0
Wrong Answer
time: 604ms
memory: 225320kb

input:

300 500000
0 5722301682716 8452307607009 329027699594 1815251343 30089254283 943061127487 44841695197962 5020142381745 3623788938103 10069313592506 5560807810421 67387215059128 1502958639680 4306022199080 36093310364434 21620815132153 1864471728058 3394408494751 1018569343784 2241919490 118027786703...

output:

734613
10782647
2207280
5946509
856568
12460967
1794098
3567882
1810184
4048539
6871107
369767
7450002
4201166
5564756
7334615
3039482
3451712
4666133
2746370
13353877
1449605
129685
1890147
7176676
2033026
4673318
455834
7962332
4529448
9026442
1036369
4394804
1476687
2092236
2258600
989444
2534375...

result:

wrong answer 1st numbers differ - expected: '113041', found: '734613'