提出 #63290355


ソースコード 拡げる

#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 400005

vector<vi> g[2];
ll d[N];

int main(void) {
	int n, m;
	ll x;
	scanf("%d%d%lld", &n, &m, &x);
	g[0].resize(n);
	g[1].resize(n);

	REP(i, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		g[0][a].pb(b);
		g[1][b].pb(a);
	}

	CL(d, -1);
	d[0] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int> > >  q;
	q.push(mp(0, 0));
	while (sz(q)) {
		pair<ll, int> top = q.top();
		q.pop();

		int id = top.Y;
		int v = top.Y / 2;
		int s = top.Y % 2;

		if (d[id] < top.X) {
			continue;
		}

		REP(i, sz(g[s][v])) {
			int u = g[s][v][i];
			if (d[u * 2 + s] == -1 || d[u * 2 + s] > d[id] + 1) {
				d[u * 2 + s] = d[id] + 1;
				q.push(mp(d[u * 2 + s], u * 2 + s));
			}
		}

		REP(i, sz(g[1 - s][v])) {
			int u = g[1 - s][v][i];
			if (d[u * 2 + 1 - s] == -1 || d[u * 2 + 1 - s] > d[id] + x + 1) {
				d[u * 2 + 1 - s] = d[id] + x + 1;
				q.push(mp(d[u * 2 + 1 - s], u * 2 + 1 - s));
			}
		}
	}

	ll ans = d[(n - 1) * 2];
	if (d[(n - 1) * 2 + 1] != -1) {
		if (ans == -1 || ans > d[(n - 1) * 2 + 1]) {
			ans = d[(n - 1) * 2 + 1];
		}
	}

	printf("%lld\n", ans);
}

提出情報

提出日時
問題 E - Flip Edge
ユーザ spiker
言語 C++ 20 (gcc 12.2)
得点 425
コード長 2596 Byte
結果 AC
実行時間 220 ms
メモリ 28368 KiB

コンパイルエラー

Main.cpp:20: warning: ignoring ‘#pragma comment ’ [-Wunknown-pragmas]
   20 | #pragma comment(linker, "/STACK:836777216")
      | 
Main.cpp: In function ‘int main()’:
Main.cpp:38:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:66:9: note: in expansion of macro ‘REP’
   66 |         REP(i, m) {
      |         ^~~
Main.cpp:38:28: note: remove parentheses
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:66:9: note: in expansion of macro ‘REP’
   66 |         REP(i, m) {
      |         ^~~
Main.cpp:38:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:90:17: note: in expansion of macro ‘REP’
   90 |                 REP(i, sz(g[s][v])) {
      |                 ^~~
Main.cpp:38:28: note: remove parentheses
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:90:17: note: in expansion of macro ‘REP’
   90 |                 REP(i, sz(g[s][v])) {
      |                 ^~~
Main.cpp:38:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:98:17: note: in expansion of macro ‘REP’
   98 |                 REP(i, sz(g[1 - s][v])) {
      |                 ^~~
Main.cpp:38:28: note: remove parentheses
   38 | #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
      |                            ^~~
Main.cpp:98:17: note: in expansion of macro ‘REP’
   98 |                 REP(i, sz(g[1 - s][v])) {
      |                 ^~~
Main.cpp:62:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |         scanf("%d%d%lld", &n, &m, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:68:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |                 scanf("%d%d", &a, &b);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 4
AC × 70
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt, 01_random_69.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 3 ms 6732 KiB
00_sample_01.txt AC 2 ms 6792 KiB
00_sample_02.txt AC 2 ms 6692 KiB
00_sample_03.txt AC 2 ms 6792 KiB
01_random_04.txt AC 209 ms 25852 KiB
01_random_05.txt AC 144 ms 21980 KiB
01_random_06.txt AC 173 ms 24668 KiB
01_random_07.txt AC 208 ms 25732 KiB
01_random_08.txt AC 143 ms 21964 KiB
01_random_09.txt AC 179 ms 24584 KiB
01_random_10.txt AC 208 ms 25712 KiB
01_random_11.txt AC 144 ms 21900 KiB
01_random_12.txt AC 176 ms 24672 KiB
01_random_13.txt AC 209 ms 25716 KiB
01_random_14.txt AC 144 ms 21972 KiB
01_random_15.txt AC 177 ms 24728 KiB
01_random_16.txt AC 207 ms 25700 KiB
01_random_17.txt AC 142 ms 22048 KiB
01_random_18.txt AC 178 ms 24600 KiB
01_random_19.txt AC 207 ms 25768 KiB
01_random_20.txt AC 144 ms 21972 KiB
01_random_21.txt AC 184 ms 24580 KiB
01_random_22.txt AC 215 ms 25740 KiB
01_random_23.txt AC 143 ms 21964 KiB
01_random_24.txt AC 185 ms 24744 KiB
01_random_25.txt AC 215 ms 25688 KiB
01_random_26.txt AC 145 ms 22048 KiB
01_random_27.txt AC 180 ms 24596 KiB
01_random_28.txt AC 220 ms 25724 KiB
01_random_29.txt AC 147 ms 21940 KiB
01_random_30.txt AC 179 ms 24572 KiB
01_random_31.txt AC 168 ms 19656 KiB
01_random_32.txt AC 29 ms 10176 KiB
01_random_33.txt AC 77 ms 15340 KiB
01_random_34.txt AC 130 ms 22364 KiB
01_random_35.txt AC 63 ms 12872 KiB
01_random_36.txt AC 92 ms 16716 KiB
01_random_37.txt AC 80 ms 12972 KiB
01_random_38.txt AC 42 ms 16936 KiB
01_random_39.txt AC 82 ms 15520 KiB
01_random_40.txt AC 123 ms 21340 KiB
01_random_41.txt AC 70 ms 18832 KiB
01_random_42.txt AC 17 ms 9020 KiB
01_random_43.txt AC 140 ms 21208 KiB
01_random_44.txt AC 47 ms 13544 KiB
01_random_45.txt AC 173 ms 23820 KiB
01_random_46.txt AC 153 ms 25220 KiB
01_random_47.txt AC 114 ms 26940 KiB
01_random_48.txt AC 154 ms 25084 KiB
01_random_49.txt AC 113 ms 26988 KiB
01_random_50.txt AC 150 ms 24988 KiB
01_random_51.txt AC 114 ms 26948 KiB
01_random_52.txt AC 161 ms 25080 KiB
01_random_53.txt AC 117 ms 26800 KiB
01_random_54.txt AC 158 ms 25104 KiB
01_random_55.txt AC 117 ms 26892 KiB
01_random_56.txt AC 168 ms 21948 KiB
01_random_57.txt AC 161 ms 21976 KiB
01_random_58.txt AC 160 ms 21972 KiB
01_random_59.txt AC 196 ms 28368 KiB
01_random_60.txt AC 186 ms 28308 KiB
01_random_61.txt AC 187 ms 28276 KiB
01_random_62.txt AC 165 ms 19480 KiB
01_random_63.txt AC 164 ms 19408 KiB
01_random_64.txt AC 165 ms 19400 KiB
01_random_65.txt AC 2 ms 6804 KiB
01_random_66.txt AC 3 ms 6984 KiB
01_random_67.txt AC 3 ms 6872 KiB
01_random_68.txt AC 7 ms 15084 KiB
01_random_69.txt AC 4 ms 10348 KiB