AtCoder Beginner Contest 061

Submission #1590927

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

class class_BellmanFord{
public:
	class_BellmanFord(){};
	virtual ~class_BellmanFord(){};
	void Init(int N);
	void Set_1Way(int a,int b, ll d);
	bool Search(int startPoint, int endPoint, ll infVal);
	double Distance(int targetPoint){return DistanceFormStart[targetPoint];}
protected:
	int PointNum=0;
	vector< multimap<int,ll> > Connect; // 相手の点番号と距離
	vector<int> BeforePoint;
	vector<ll> DistanceFormStart;
};

void class_BellmanFord::Init(int N){
	Connect.clear();
	Connect.resize(N);
	DistanceFormStart.clear();
	DistanceFormStart.resize(N);
	BeforePoint.clear();
	BeforePoint.resize(N);

	PointNum = N;
}

void class_BellmanFord::Set_1Way(int a, int b, ll d){
	Connect[a].emplace(b,d);
}

bool class_BellmanFord::Search(int startPoint, int endPoint, ll infVal){
	for(int i=0;i<PointNum;i++){
		DistanceFormStart[i] = infVal;
		BeforePoint[i] = -1;
	}
	DistanceFormStart[startPoint] = 0;

	for(int i=0;i<PointNum-1;i++){
		for(int u=0;u<PointNum;u++){
			if (DistanceFormStart[u]==infVal){continue;}
			for(auto c : Connect[u]){
				double newScore = DistanceFormStart[u] + c.second;
				if (newScore < DistanceFormStart[c.first]){
					DistanceFormStart[c.first] = newScore;
					BeforePoint[c.first] = u;
				}
			}
		}
	}

	vector<char> nega(PointNum);
	for(int i=0;i<PointNum;i++){
		for(int u=0;u<PointNum;u++){
			if (DistanceFormStart[u]==infVal){continue;}
			for(auto c : Connect[u]){
				double newScore = DistanceFormStart[u] + c.second;
				if (newScore < DistanceFormStart[c.first]){
					DistanceFormStart[c.first] = newScore;
					nega[c.first]=1;
				}

				if (nega[u]==1){
					nega[c.first]=1;
				}
			}
		}
	}
	// endPoint に届かない所の負ループは無視!

	if (nega[endPoint]==1){return false;}
	return true;
}


int main(int , char **)
{
	int N,M;
	cin >> N >> M;

	class_BellmanFord graph;
	graph.Init(N);

	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--; 	// 入力は1始点、これを 0 始点とする
		graph.Set_1Way(a,b,-c);
	}

	if (graph.Search(0,N-1,LLONG_MAX) == false){printf("inf\n");return 0;}
	double ans = graph.Distance(N-1);
	printf("%ld\n", (ll)(ans * -1.0) );

	return 0;
}

Submission

Task問題 D - Score Attack
User nameユーザ名 t_tkd3a
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 2340 Byte
File nameファイル名
Exec time実行時間 43 ms
Memory usageメモリ使用量 384 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
All 400 / 400 sample_01.txt,sample_02.txt,sample_03.txt,subtask_1_1.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_2.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_1_26.txt,subtask_1_27.txt,subtask_1_3.txt,subtask_1_4.txt,subtask_1_5.txt,subtask_1_6.txt,subtask_1_7.txt,subtask_1_8.txt,subtask_1_9.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_1.txt AC 4 ms 256 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 4 ms 256 KB
subtask_1_12.txt AC 24 ms 384 KB
subtask_1_13.txt AC 4 ms 256 KB
subtask_1_14.txt AC 20 ms 384 KB
subtask_1_15.txt AC 43 ms 384 KB
subtask_1_16.txt AC 1 ms 256 KB
subtask_1_17.txt AC 1 ms 256 KB
subtask_1_18.txt AC 13 ms 384 KB
subtask_1_19.txt AC 30 ms 384 KB
subtask_1_2.txt AC 17 ms 384 KB
subtask_1_20.txt AC 3 ms 256 KB
subtask_1_21.txt AC 16 ms 384 KB
subtask_1_22.txt AC 38 ms 384 KB
subtask_1_23.txt AC 1 ms 256 KB
subtask_1_24.txt AC 23 ms 384 KB
subtask_1_25.txt AC 6 ms 256 KB
subtask_1_26.txt AC 17 ms 384 KB
subtask_1_27.txt AC 17 ms 384 KB
subtask_1_3.txt AC 11 ms 384 KB
subtask_1_4.txt AC 17 ms 384 KB
subtask_1_5.txt AC 7 ms 256 KB
subtask_1_6.txt AC 17 ms 384 KB
subtask_1_7.txt AC 15 ms 384 KB
subtask_1_8.txt AC 17 ms 384 KB
subtask_1_9.txt AC 1 ms 256 KB