結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
akun0716
|
| 提出日時 | 2020-11-08 10:47:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 307 ms / 2,000 ms |
| コード長 | 3,246 bytes |
| コンパイル時間 | 1,233 ms |
| コンパイル使用メモリ | 98,152 KB |
| 実行使用メモリ | 79,616 KB |
| 最終ジャッジ日時 | 2024-11-16 07:09:28 |
| 合計ジャッジ時間 | 6,491 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;
struct edge { int to, cost; };
#define LLINF 922337203685477580
int N, M;
vector<vector<edge> > G;
VI d;
int t[510][510][2];
int co[510][510];
void dikstra(int s) {
priority_queue<pii, vector<pii>, greater<pii> >que;
REP(i, N)d[i] = LLINF;
d[s] = 0;
que.push(pii(0, s));
while (!que.empty()) {
pii p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)continue;
REP(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int pt = 0;
cin >> N >> M;
int n = N;
REP(i, N)REP(j, N) {
REP(k, 2)t[i][j][k] = pt++;
co[i][j] = 1;
}
N = N * N * 2;
G.resize(N);
d.resize(N);
REP(i, M) {
int x, y, c; cin >> x >> y >> c;
x--; y--;
co[x][y] += c;
}
REP(i, n)REP(j, n) {
int now = t[i][j][0];
int to;
if (i + 1 < n) {
to = t[i + 1][j][0];
G[now].push_back((edge) { to, co[i + 1][j] });
if (co[i + 1][j] > 1) {
to = t[i + 1][j][1];
G[now].push_back((edge) { to, 1 });
}
}
if (i - 1 >= 0) {
to = t[i - 1][j][0];
G[now].push_back((edge) { to, co[i - 1][j] });
if (co[i - 1][j] > 1) {
to = t[i - 1][j][1];
G[now].push_back((edge) { to, 1 });
}
}
if (j + 1 < n) {
to = t[i][j + 1][0];
G[now].push_back((edge) { to, co[i][j + 1] });
if (co[i][j + 1] > 1) {
to = t[i][j + 1][1];
G[now].push_back((edge) { to, 1 });
}
}
if (j - 1 >= 0) {
to = t[i][j - 1][0];
G[now].push_back((edge) { to, co[i][j - 1] });
if (co[i][j - 1] > 1) {
to = t[i][j - 1][1];
G[now].push_back((edge) { to, 1 });
}
}
now = t[i][j][1];
if (i + 1 < n) {
to = t[i + 1][j][1];
G[now].push_back((edge) { to, co[i + 1][j] });
}
if (i - 1 >= 0) {
to = t[i - 1][j][1];
G[now].push_back((edge) { to, co[i - 1][j] });
}
if (j + 1 < n) {
to = t[i][j + 1][1];
G[now].push_back((edge) { to, co[i][j + 1] });
}
if (j - 1 >= 0) {
to = t[i][j - 1][1];
G[now].push_back((edge) { to, co[i][j - 1] });
}
}
dikstra(t[0][0][0]);
cout << d[t[n - 1][n - 1][1]] << endl;
return 0;
}
akun0716