Submission #1420223
Source Code Expand
#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(){
while(1);
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);
else if(check(b[i][j].x-1,b[i][j].y))
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 Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
Wuvin |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1745 Byte |
Status |
WA |
Exec Time |
2104 ms |
Memory |
15104 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:23:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:24: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]]++;
^
Judge Result
Set Name |
sample |
All |
Score / Max Score |
0 / 0 |
0 / 1500 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
All |
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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
TLE |
2104 ms |
14464 KB |
01-02.txt |
TLE |
2103 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 |
AC |
11 ms |
5632 KB |
01-07.txt |
WA |
27 ms |
6144 KB |
01-08.txt |
WA |
28 ms |
6144 KB |
01-09.txt |
WA |
21 ms |
5760 KB |
01-10.txt |
AC |
18 ms |
5760 KB |
01-11.txt |
AC |
25 ms |
5888 KB |
01-12.txt |
AC |
24 ms |
5888 KB |
01-13.txt |
AC |
82 ms |
13696 KB |
01-14.txt |
AC |
80 ms |
14068 KB |
01-15.txt |
AC |
72 ms |
15104 KB |
01-16.txt |
AC |
16 ms |
5760 KB |
01-17.txt |
AC |
16 ms |
5760 KB |
01-18.txt |
AC |
16 ms |
5760 KB |
01-19.txt |
AC |
80 ms |
13628 KB |
01-20.txt |
WA |
78 ms |
12280 KB |
01-21.txt |
WA |
80 ms |
12408 KB |
01-22.txt |
WA |
54 ms |
9224 KB |
01-23.txt |
TLE |
2103 ms |
6144 KB |
01-24.txt |
TLE |
2103 ms |
6144 KB |
01-25.txt |
TLE |
2103 ms |
6016 KB |
01-26.txt |
TLE |
2103 ms |
6016 KB |
01-27.txt |
TLE |
2103 ms |
6016 KB |
01-28.txt |
TLE |
2103 ms |
6144 KB |
01-29.txt |
TLE |
2103 ms |
5632 KB |
01-30.txt |
TLE |
2103 ms |
5632 KB |
01-31.txt |
TLE |
2103 ms |
5632 KB |
sample-01.txt |
AC |
3 ms |
5632 KB |
sample-02.txt |
TLE |
2103 ms |
5632 KB |