結果

問題 No.614 壊れたキャンパス
ユーザー Sebastian KingSebastian King
提出日時 2017-12-14 00:20:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,718 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 156,356 KB
最終ジャッジ日時 2024-05-08 08:01:51
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
144,000 KB
testcase_01 AC 109 ms
143,940 KB
testcase_02 AC 109 ms
143,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 109 ms
143,812 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 177 ms
149,576 KB
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

ll K;
int S, T;
vector<int> E[MAXN];
vector<PII> F[MAXN];
vector<ll> D[MAXN];
const ll INF = 1ll << 60;

int tag1[MAXN], tag2[MAXN];

void solve(int casi){
//	cout << "Case #" << casi << ": ";
	cin >> n >> m >> K >> S >> T;
	E[1].push_back(S);
	E[n].push_back(T);
	for (int i = 1; i <= n; i++){
		int x, y, z;
		cin >> x >> y >> z;
		E[x].push_back(y);
		E[x+1].push_back(z);
		F[x].push_back(PII(y, z));
	}
	sort(E[1].begin(), E[1].end());
	for (auto &x : E[1]){
		D[1].push_back(abs(x - S));
	}
	for (int i = 1; i < n; i++){
		sort(E[i+1].begin(), E[i+1].end());
		sort(F[i].begin(), F[i].end());
		D[i+1].resize(E[i+1].size());
		int n2 = E[i+1].size(), n1 = E[i].size();
		for (int j = 0; j < E[i].size(); j++)
			tag1[E[i][j]] = j;
		for (int j = 0; j < E[i + 1].size(); j++)
			tag2[E[i + 1][j]] = j;
		for (int j = 0; j < n2; j++)
			D[i+1][j] = INF;
		for (auto &x : F[i]){
			D[i+1][tag2[x.second]] = min(D[i+1][tag2[x.second]], D[i][tag1[x.first]]/* + abs(x.first - x.second)*/);
		}
		for (int j = 1; j < n2; j++){
			D[i+1][j] = min(D[i+1][j], D[i+1][j-1] + abs(E[i+1][j] - E[i+1][j-1]));
		}
		for (int j = n2 - 2; j >= 0; j--){
			D[i+1][j] = min(D[i+1][j], D[i+1][j+1] + abs(E[i+1][j] - E[i+1][j+1]));
		}
	}
	if (D[n][tag2[T]] >= INF)
		D[n][tag2[T]] = -1;
	cout << D[n][tag2[T]] << endl;
}

void printans(){

}


int main(){
	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}

0