結果
| 問題 |
No.2213 Neq Move
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-05 11:57:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,901 bytes |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 63,308 KB |
| 最終ジャッジ日時 | 2025-02-22 02:13:32 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%d%d%d%d", &a, &b, &c, &d); // a->c, b->d
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2213.cc: No.2213 Neq Move - yukicoder
*/
#include<cstdio>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_M = 4 + 2;
const int MAX_N = MAX_M * MAX_M;
const int INF = 1 << 30;
const long long LINF = 1LL << 62;
/* typedef */
using ll = long long;
using pli = pair<ll,int>;
/* global variables */
int es[MAX_N][MAX_N];
ll ds[MAX_N];
/* subroutines */
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d); // a->c, b->d
int as[] = { 0, 1, a, b, c, d };
sort(as, as + 6);
int m = unique(as, as + 6) - as;
int n = m * m;
int st = -1, gl = -1;
for (int u = 0; u < n; u++) {
fill(es[u], es[u] + n, INF);
es[u][u] = 0;
int ux = u / m, uy = u % m;
if (as[ux] == a && as[uy] == b) st = u;
if (as[ux] == c && as[uy] == d) gl = u;
if (ux == uy) continue;
for (int v = 0; v < n; v++) {
int vx = v / m, vy = v % m;
if (u == v || vx == vy) continue;
if (ux == vx) {
if (uy < vy && (ux < uy || vy < ux))
es[u][v] = as[vy] - as[uy];
else if (vy == 0)
es[u][v] = 1;
}
if (uy == vy) {
if (ux < vx && (uy < ux || vx < uy))
es[u][v] = as[vx] - as[ux];
else if (vx == 0)
es[u][v] = 1;
}
}
}
//for (int i = 0; i < m; i++) printf(" %d", as[i]); putchar('\n');
//printf(" st=%d, gl=%d\n", st, gl);
fill(ds, ds + n, LINF);
ds[st] = 0;
priority_queue<pli> q;
q.push({0, st});
while (! q.empty()) {
auto [ud, u] = q.top(); q.pop();
ud = -ud;
if (ds[u] != ud) continue;
for (int v = 0; v < n; v++)
if (es[u][v] < INF) {
ll vd = ud + es[u][v];
if (ds[v] > vd) {
ds[v] = vd;
q.push({-vd, v});
}
}
}
printf("%lld\n", ds[gl]);
}
return 0;
}
tnakao0123