結果

問題 No.1283 Extra Fee
ユーザー HaaHaa
提出日時 2020-11-06 22:22:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,406 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 176,692 KB
実行使用メモリ 11,216 KB
最終ジャッジ日時 2023-09-29 19:02:18
合計ジャッジ時間 8,748 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,596 KB
testcase_01 AC 3 ms
5,396 KB
testcase_02 AC 3 ms
5,396 KB
testcase_03 AC 3 ms
5,692 KB
testcase_04 WA -
testcase_05 AC 3 ms
5,596 KB
testcase_06 AC 3 ms
5,392 KB
testcase_07 AC 3 ms
5,472 KB
testcase_08 AC 3 ms
5,452 KB
testcase_09 AC 3 ms
5,396 KB
testcase_10 AC 3 ms
5,404 KB
testcase_11 AC 10 ms
5,808 KB
testcase_12 AC 13 ms
5,792 KB
testcase_13 AC 11 ms
5,628 KB
testcase_14 AC 42 ms
6,184 KB
testcase_15 AC 66 ms
6,328 KB
testcase_16 AC 15 ms
5,668 KB
testcase_17 AC 130 ms
10,700 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 188 ms
9,148 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 140 ms
11,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ll bfs(int, int, int, int)’ 内:
main.cpp:40:60: 警告: narrowing conversion of ‘(((__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)(d + 1)) + (& c.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)tox)))->std::vector<long long int>::operator[](((std::vector<long long int>::size_type)toy)))’ from ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} to ‘int’ [-Wnarrowing]
   40 |                                         q.push({tox,toy,d+1+c[tox][toy],0});
main.cpp:50:60: 警告: narrowing conversion of ‘(((__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)(d + 1)) + (& c.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)tox)))->std::vector<long long int>::operator[](((std::vector<long long int>::size_type)toy)))’ from ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} to ‘int’ [-Wnarrowing]
   50 |                                         q.push({tox,toy,d+1+c[tox][toy],1});

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
const ll MOD=1000000007;
const ll INF=1e18;

struct xy {
	int x; int y; int d; bool f;
	bool operator<(const xy &another) const {return d > another.d;};
};
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int n;
VVI c(510,VI(510,0));

ll bfs(int sx, int sy, int gx, int gy){
	priority_queue<xy> q;
	q.push({sx,sy,0,0});
	VVI dis0(n, VI(n, INF));
	VVI dis1(n, VI(n, INF));
	while (!q.empty()) {
		int x=q.top().x, y=q.top().y, d=q.top().d;
		bool f=q.top().f;
		q.pop();
		if(!f&&d>dis0[x][y])
			continue;
		if(f&&d>dis1[x][y])
			continue;
		REP(k,4){
			int tox=x+dx[k], toy=y+dy[k];
			if(tox<0||tox>=n||toy<0||toy>=n)
				continue;
			if(!f){
				if(dis0[tox][toy]>d+1+c[tox][toy]){
					dis0[tox][toy]=d+1+c[tox][toy];
					q.push({tox,toy,d+1+c[tox][toy],0});
				}
				if(dis1[tox][toy]>d+1){
					dis1[tox][toy]=d+1;
					q.push({tox,toy,d+1,1});
				}
			}
			else{
				if(dis1[tox][toy]>d+1+c[tox][toy]){
					dis1[tox][toy]=d+1+c[tox][toy];
					q.push({tox,toy,d+1+c[tox][toy],1});
				}
			}
		}
	}
	return dis1[gx][gy];
}

int main(){
	int m; cin >> n >> m;
	int h, w, x;
	REP(i,m){
		cin >> h >> w >> x;
		h--, w--;
		c[h][w]=x;
	}
	cout << bfs(0,0,n-1,n-1) << endl;
	return 0;
}
0