QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21366 | #1274. Walking Plan | FudanU1# | WA | 1128ms | 4836kb | C++17 | 2.7kb | 2022-03-04 17:08:54 | 2022-05-08 02:56:18 |
Judging History
answer
#pragma GCC optimize(3)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct matrix {
int n , m;
int a[60][60];
} ini[120] , ini100[120] , now;
int n , m , q;
int dis[120][120];
int ans;
void clear () {
}
matrix operator * ( matrix x1 , matrix x2 ) {
int i , j , k;
matrix y;
y.n = x1.n; y.m = x2.m;
for ( i = 1 ; i <= y.n ; i++ ) {
for ( j = 1 ; j <= y.m ; j++ ) {
y.a[i][j] = -1;
}
}
for ( i = 1 ; i <= x1.n ; i++ ) {
for ( j = 1 ; j <= x1.m ; j++ ) {
if ( x1.a[i][j] == -1 ) continue;
for ( k = 1 ; k <= x2.m ; k++ ) {
if ( x2.a[j][k] != -1 ) {
if ( y.a[i][k] == -1 ) y.a[i][k] = x1.a[i][j] + x2.a[j][k];
else y.a[i][k] = min ( y.a[i][k] , x1.a[i][j] + x2.a[j][k] );
}
}
}
}
return y;
}
void work () {
int i , j , k , u , v , w;
int s , t;
//n = 50; m = 2500;
scanf ( "%d%d" , &n , &m );
for ( i = 1 ; i <= n ; i++ ) {
for ( j = 1 ; j <= n ; j++ ) {
dis[i][j] = -1;
}
}
for ( i = 1 ; i <= m ; i++ ) {
/*u = (i-1) / n + 1;
v = (i-1) % n + 1;
w = rand () % 10000;*/
scanf ( "%d%d%d" , &u , &v , &w );
if ( dis[u][v] == -1 ) dis[u][v] = w;
else dis[u][v] = min ( dis[u][v] , w );
}
for ( i = 1 ; i <= n ; i++ ) {
for ( j = 1 ; j <= n ; j++ ) {
ini[1].a[i][j] = dis[i][j];
}
}
ini[1].n = ini[1].m = n;
for ( i = 2 ; i <= 100 ; i++ ) {
ini[i] = ini[1] * ini[i-1];
}
ini[0].n = ini[0].m = ini100[0].n = ini100[0].m = n;
for ( i = 1 ; i <=n ; i++ ) {
for ( j = 1 ; j <= n ; j++ ) {
ini[0].a[i][j] = ini100[0].a[i][j] = -1;
}
ini[0].a[i][i] = ini100[0].a[i][i] = 0;
}
ini100[1] = ini[100];
for ( i = 2 ; i <= 100 ; i++ ) {
ini100[i] = ini100[1] * ini100[i-1];
}
for ( i = 1 ; i <= n ; i++ ) {
dis[i][i] = 0;
}
for ( k = 1 ; k <= n ; k++ ) {
for ( i = 1 ; i <= n ; i++ ) {
for ( j = 1 ; j <= n ; j++ ) {
if ( dis[i][k] != -1 && dis[k][j] != -1 ) {
if ( dis[i][j] == -1 ) dis[i][j] = dis[i][k] + dis[k][j];
else dis[i][j] = min ( dis[i][j] , dis[i][k] + dis[k][j] );
}
}
}
}
//q = 100000;
scanf ( "%d" , &q );
for ( i = 1 ; i <= q ; i++ ) {
/*s = rand () % n + 1;
t = rand () % n + 1;
k = rand () % 10000 + 1;*/
scanf ( "%d%d%d" , &s , &t , &k );
now.n = 1;
now.m = n;
for ( j = 1; j <= n ; j++ ) now.a[1][j] = ini[k%100].a[s][j];
now = now * ini100[k/100];
ans = -1;
for ( j = 1 ; j <= n ; j++ ) {
if ( now.a[s][j] != -1 && dis[j][t] != -1 ) {
if ( ans == -1 ) ans = now.a[s][j] + dis[j][t];
else ans = min ( ans , now.a[s][j] + dis[j][t] );
}
}
printf ( "%d\n" , ans );
}
}
int main () {
int t;
scanf ( "%d" , &t );
while ( t-- ) {
work ();
clear ();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4820kb
input:
2 3 3 1 2 1 2 3 10 3 1 100 3 1 1 1 1 2 1 1 3 1 2 1 1 2 1 1 2 1 1
output:
111 1 11 -1
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 1128ms
memory: 4836kb
input:
10 5 10 4 2 55 2 1 26 3 4 83 5 2 16 4 5 54 3 4 38 2 1 68 2 5 1 4 5 85 4 2 60 20 2 1 13 1 4 17 3 2 20 2 4 16 4 2 17 4 2 2 3 1 2 1 5 10 2 1 8 4 5 15 4 2 16 3 1 18 5 2 7 4 2 9 4 3 16 1 4 18 3 2 5 1 5 9 5 1 19 1 2 16 20 50 4 16 25 3 16 990 9 18 863 19 12 236 4 10 360 13 4 585 14 17 164 8 18 198 2 17 804...
output:
85026 -1 85076 -1 85053 85053 85100 -1 85026 85039 85053 85100 85016 85053 -1 -1 85076 -1 85025 -1 -1 3625000 3624724 3625853 3624372 3624395 3625944 3624709 3623965 3625101 3624559 -1 3625314 3624564 3625525 3625101 3624053 5108 3624903 13020 3625056 3624787 3625077 3625220 3625101 15863 3625013 36...
result:
wrong answer 1st lines differ - expected: '128', found: '85026'