CODE FESTIVAL 2016 Exhibition(Parallel)

Submission #1420228

Source codeソースコード

#include<bits/stdc++.h>
#define pii pair<int,int>
#define N 100005
#define fr first
#define se second
#define check(x,y) (mp.find(make_pair(x,y))!=mp.end())
using namespace std;
struct msg{
	int x,y,num;
};
pii v[N];
vector<msg> b[N*2];
map<pii,int > mp;
map<pii,int >::iterator itr;
int dp[N][2];
int n,ans,d;
void end(){
	puts("-1");
	exit(0);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&v[i].first,&v[i].se),mp[v[i]]++;
	d=v[1].se;
	for(itr=mp.begin();itr!=mp.end();itr++){
		b[(itr->fr).fr+(itr->fr).se].push_back((msg){(itr->fr).fr,(itr->fr).se,itr->se});
	}
	for(int i=0;i<d;i++) if(b[i].size()>0) end();
	if(mp[v[1]]!=1||mp[v[2]]!=1||v[1].fr!=0||v[2].se!=0||v[1].se!=v[2].fr) end();
	
	for(int i=d;i<=n*2;i++){
		for(int j=0;j<b[i].size();j++){
			dp[j][0]=dp[j][1]=0x3f3f3f3f;
			if(j==0){
				if(i==d) {dp[j][0]=0;continue;}
				if(check(b[i][j].x-1,b[i][j].y-1)){
					dp[j][0]=dp[j][1]=b[i][j].num;
				}else if(check(b[i][j].x-1,b[i][j].y)){
					dp[j][0]=b[i][j].num;
					if(check(b[i][j].x,b[i][j].y-1))
						dp[j][1]=b[i][j].num*2;
				}else end();
			}else{
				int temp=0x3f3f3f3f;
				if(b[i][j-1].x+1==b[i][j].x)
					temp=dp[j-1][0]+max(b[i][j].num,b[i][j-1].num);
				if(check(b[i][j].x-1,b[i][j].y))
					temp=max(temp,dp[j-1][1]+b[i][j].num);
				dp[j][0]=temp;
				
				if(check(b[i][j].x,b[i][j].y-1))
					temp+=b[i][j].num;
				else temp=0x3f3f3f3f;
				if(check(b[i][j].x-1,b[i][j].y-1)) temp=min(temp,min(dp[j-1][1],dp[j][0])+b[i][j].num);
				dp[j][0]=min(dp[j][0],dp[j][1]=temp);
			}
		}
		if(i==d) ans+=dp[b[i].size()-1][0];
		else ans+=dp[b[i].size()-1][1];
		if(ans>1e9) end();
	}
	printf("%d\n",ans);
	return 0;
}

Submission

Task問題 A - Distance Pairs
User nameユーザ名 Wuvin
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1738 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:22:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:23:69: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%d%d",&v[i].first,&v[i].se),mp[v[i]]++;
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 0 / 1500 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,01-31.txt,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 71 ms 14464 KB
01-02.txt AC 19 ms 5760 KB
01-03.txt AC 3 ms 5632 KB
01-04.txt AC 3 ms 5632 KB
01-05.txt AC 3 ms 5632 KB
01-06.txt WA
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt AC 25 ms 5888 KB
01-12.txt AC 24 ms 5888 KB
01-13.txt AC 81 ms 13592 KB
01-14.txt AC 78 ms 14068 KB
01-15.txt AC 73 ms 15104 KB
01-16.txt AC 16 ms 5760 KB
01-17.txt AC 16 ms 5760 KB
01-18.txt AC 17 ms 5760 KB
01-19.txt AC 87 ms 13628 KB
01-20.txt WA
01-21.txt WA
01-22.txt WA
01-23.txt AC 26 ms 6144 KB
01-24.txt AC 28 ms 6144 KB
01-25.txt AC 25 ms 6016 KB
01-26.txt AC 25 ms 6016 KB
01-27.txt AC 25 ms 6016 KB
01-28.txt AC 26 ms 6144 KB
01-29.txt AC 3 ms 5632 KB
01-30.txt AC 3 ms 5632 KB
01-31.txt AC 3 ms 5632 KB
sample-01.txt AC 3 ms 5632 KB
sample-02.txt AC 3 ms 5632 KB