QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#840829 | #9903. 最短路径 | Justinshao | 0 | 208ms | 12436kb | C++20 | 3.5kb | 2025-01-03 06:15:15 | 2025-01-03 06:15:15 |
Judging History
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));
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 (l, 0, 3) {
rep (k, l, mid + 1) {
dis[k][k] = 0;
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 (l, 0, 3) {
rep (k, mid + 1, r + 1) {
dis[k][k] = 0;
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: 203ms
memory: 12408kb
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:
65676043 21708267 2723317 45878164 300451 1463718 46686875 7489420 1589266 350083 3053747 432111 1291868 12215270 40627898 460269 4163602 56363759 1914167 25066838 3219637 321631 21822925 7225976 65846545 4963160 1454333 3750900 56646822 5418133 4824788 6475859 7326489 51434455 2070324 1218336 32189...
result:
wrong answer 2nd numbers differ - expected: '128648', found: '21708267'
Test #2:
score: 0
Wrong Answer
time: 208ms
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 334851 2375637 10003505 8445945 1442740 29454249 13943335 4051627 13533174 4201167 846978 5115384 37653844 4475089 6185496 4671343 2269543 28444452 50707966 5186723 8042120 322009 6201248 13499544 339669 4263174 4108070 17699293 23165961 200708242 7413464 8456596 2890762 3082517 107295 7078...
result:
wrong answer 1st numbers differ - expected: '270396', found: '13978568'
Test #3:
score: 0
Wrong Answer
time: 207ms
memory: 12300kb
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:
27009138 25190264 4467202 1156053 2916029 14225289 15473789 909395 4425070 3797235 1892999 3429807 987738 8703866 82811357 1616486 8304714 96369937 91338615 1929592 2979089 951355 1333704 8304714 4464059 16959942 9449560 10965134 386763 25087909 17053943 24039018 1603846 5188432 8425276 5878747 1890...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '27009138'
Test #4:
score: 0
Time Limit Exceeded
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:
result:
Test #5:
score: 0
Time Limit Exceeded
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:
result:
Test #6:
score: 0
Time Limit Exceeded
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:
result:
Test #7:
score: 0
Time Limit Exceeded
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:
result:
Test #8:
score: 0
Time Limit Exceeded
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:
result:
Test #9:
score: 0
Time Limit Exceeded
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:
result:
Test #10:
score: 0
Time Limit Exceeded
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...