QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#81779 | #1274. Walking Plan | Reanap | WA | 787ms | 8296kb | C++14 | 2.4kb | 2023-02-26 11:57:10 | 2023-02-26 11:57:14 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair <int , int>
#define pll pair <LL , LL>
#define mp make_pair
#define fs first
#define sc second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
//const int Mxdt=100000;
//static char buf[Mxdt],*p1=buf,*p2=buf;
//#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
template <typename T>
void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
x *= f;
}
template <typename T>
void write(T x , char s='\n') {
if(!x) {putchar('0');putchar(s);return;}
if(x<0) {putchar('-');x=-x;}
T t = 0 , tmp[25] = {};
while(x) tmp[t ++] = x % 10 , x /= 10;
while(t -- > 0) putchar(tmp[t] + '0');
putchar(s);
}
const LL inf = 1e18;
LL dis1[105][55][55] , dis2[105][55][55] , dis[55][55];
int n , m;
int main() {
int T;read(T);
while(T -- > 0) {
for (int i = 0; i <= 100; ++i) for (int j = 0; j <= 50; ++j) for (int k = 0; k <= 50; ++k) {
dis1[i][j][k] = dis2[i][j][k] = inf;
dis[j][k] = inf;
if(j == k && !i) dis1[i][j][k] = dis2[i][j][k] = dis[j][k] = 0;
if(j == k) dis[j][k] = 0;
}
read(n),read(m);
for (int i = 1; i <= m; ++i) {
int u , v;LL w;
read(u),read(v),read(w);
dis1[1][u][v] = min(dis1[1][u][v] , w);
dis[u][v] = min(dis[u][v] , w);
}
for (int u = 1; u <= n; ++u) for (int k = 1; k <= n; ++k) for (int v = 1; v <= n; ++v) {
dis[u][v] = min(dis[u][v] , dis[u][k] + dis[k][v]);
}
for (int i = 2; i <= 100; ++i) {
for (int u = 1; u <= n; ++u) for (int k = 1; k <= n; ++k) for (int v = 1; v <= n; ++v) {
dis1[i][u][v] = min(dis1[i][u][v] , dis1[i - 1][u][k] + dis1[i - 1][k][v]);
}
}
for (int u = 1; u <= n; ++u) for (int v = 1; v <= n; ++v) dis2[1][u][v] = dis1[100][u][v];
for (int i = 2; i <= 100; ++i) {
for (int u = 1; u <= n; ++u) for (int k = 1; k <= n; ++k) for (int v = 1; v <= n; ++v) {
dis2[i][u][v] = min(dis2[i][u][v] , dis2[i - 1][u][k] + dis2[i - 1][k][v]);
}
}
int Q;read(Q);
while(Q -- > 0) {
int s , t , k;
read(s),read(t),read(k);
int p = k / 100 , q = k % 100;
LL ans = inf;
for (int w = 1; w <= n; ++w) for (int d = 1; d <= n; ++d) ans = min(ans , dis1[q][s][w] + dis2[p][w][d] + dis[d][t]);
if(ans != inf) write(ans);
else puts("-1");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8208kb
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: 787ms
memory: 8296kb
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:
34842 -1 4456524 -1 557109 70 119 -1 1114 139303 278581 1114212 560 2229 -1 -1 212 -1 2228249 -1 -1 -1 46964 25501632889987396 25501632889986073 -1 -1 -1 12160126269 -1 3040031996 -1 47852 760008709 95002141 -1 -1 1484807 -1 6225984592727 -1 372152 24446 -1 47228 398463013907027 743558 -1 -1 9961575...
result:
wrong answer 1st lines differ - expected: '128', found: '34842'