Submission #43430

# Submission time Handle Problem Language Result Execution time Memory
43430 2018-03-16T05:44:07 Z duiceman Palembang Bridges (APIO15_bridge) C++14
0 / 100
7 ms 3868 KB
#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define umap unordered_map
#define pqueue priority_queue
#define mset multiset
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(),x.end()
#define long long long
#define MOD 1000000007
#define MAX (long)(1e16+5)
#define MIN (long)(-1e16-5)
#define FILEIN_ freopen("__in.txt","r",stdin)
#define FILEOUT_ freopen("__out.txt","w",stdout)
#define FILEIO_ freopen("__in.txt","r",stdin),freopen("__out.txt","w",stdout)
#define FILEIN(text) freopen(text,"r",stdin)
#define FILEOUT(text) freopen(text,"w",stdout)
#define FILEIO(text) freopen(text".in","r",stdin),freopen(text".out","w",stdout)

char c1[5],c2[5];
umap<long,long> in,out;
pair<long,long> a[100005];

main(){
	long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
	set<long> pos;
	in.reserve(200005);
	out.reserve(200005);
	double med;
	
	scanf("%lld %lld",&m,&n);
	if(m != 1) return 136;
	for(i = 1; i <= n; i++){
		scanf("%s %lld %s %lld",c1,&x,c2,&y);
		x++;
		y++;
		if(x > y) swap(x,y);
		res += y-x;
		if(c1[0] == c2[0]){
			n--;
			i--;
			continue;
		}
		a[i] = {x,y};
		med += (double)(x+y)/2.0;
		res++;
		in[x]++;
		out[y]++;
		pos.emplace(x);
		pos.emplace(y);
	}
	med /= (double)n;
//	printf("%.2lf\n",med);
	m1 = (long)med;
	r1 = res;
	for(i = 1; i <= n; i++){
		if(m1 >= a[i].x && m1 <= a[i].y) continue;
		r1 += min(abs(a[i].x-m1),abs(a[i].y-m1))*2;
	}
	m2 = (long)ceil(med);
	r2 = res;
	for(i = 1; i <= n; i++){
		if(m2 >= a[i].x && m2 <= a[i].y) continue;
		r2 += min(abs(a[i].x-m2),abs(a[i].y-m2))*2;
	}
	printf("%lld\n",min(r1,r2));

	/*l = r = 0;
	for(long x : pos){
		res += x*2*in[x];
		r += in[x];
	}
	y = 0;
	for(long x : pos){
		res -= (x-y)*r*2;
		res += (x-y)*l*2;
		r -= in[x];
		l += out[x];
		mn = min(mn,res);
		y = x;
	}
	printf("%lld\n",mn);*/

	return 0;	
}

Compilation message

bridge.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bridge.cpp: In function 'int main()':
bridge.cpp:29:7: warning: unused variable 't' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
       ^
bridge.cpp:29:11: warning: unused variable 'j' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
           ^
bridge.cpp:29:13: warning: unused variable 'k' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
             ^
bridge.cpp:29:29: warning: unused variable 'l' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
                             ^
bridge.cpp:29:33: warning: unused variable 'r' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
                                 ^
bridge.cpp:29:37: warning: unused variable 'mn' [-Wunused-variable]
  long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,m1,m2,r1,r2;
                                     ^
bridge.cpp:35:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&m,&n);
                          ^
bridge.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s %lld %s %lld",c1,&x,c2,&y);
                                       ^
bridge.cpp:49:27: warning: 'med' may be used uninitialized in this function [-Wmaybe-uninitialized]
   med += (double)(x+y)/2.0;
                           ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 4 ms 3752 KB Output is correct
4 Incorrect 5 ms 3820 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3820 KB Output is correct
2 Correct 4 ms 3820 KB Output is correct
3 Correct 4 ms 3820 KB Output is correct
4 Incorrect 7 ms 3868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 3868 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 3868 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 3868 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -