Submission #403497

# Submission time Handle Problem Language Result Execution time Memory
403497 2021-05-13T08:44:55 Z jamezzz None (KOI16_laser) C++14
19 / 100
2 ms 768 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

//#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;

int n,x,y,t,id,pfx[9005];
ii ans[3005];
vector<iiii> v;

void dnc(vii vv){
	int s;
	int m=sz(vv);
	vii a;
	for(int i=0;i<m;++i){
		if(vv[i].fi==0){
			s=i;break;
		}
	}
	for(int i=s;i<m;++i)a.pb(vv[i]);
	for(int i=0;i<s;++i)a.pb(vv[i]);
	for(int i=0;i<m;++i){
		if(i==0)pfx[i]=a[i].fi;
		else pfx[i]=pfx[i-1]+a[i].fi;
	}
	#ifdef DEBUG
	pf("dnc: %d\n",s);
	for(ii p:a){
		pf("%d %d\n",p.fi,p.se);
	}
	#endif //DEBUG
	for(int i=0;i<m;++i){
		if(a[i].fi==0||a[(i+1)%m].fi==0)continue;
		bool pos=true;
		if(i!=1){
			int cnt=pfx[i-1]-pfx[0];
			int sz=i-1;
			pos=pos&&(cnt%2==0&&cnt/2*3==sz);
		}
		if(i+1!=m-1){
			int cnt=pfx[m-1]-pfx[i+1];
			int sz=m-(i+2);
			pos=pos&&(cnt%2==0&&cnt/2*3==sz);
		}
		debug("%d\n",i);
		if(pos){
			debug("done\n");
			ans[a[0].se]=ii(a[i].se,a[i+1].se);
			if(i!=1){
				vii vl;
				for(int x=1;x<i;++x){
					vl.pb(a[x]);
				}
				dnc(vl);
			}
			if(i+1!=m-1){
				vii vr;
				for(int x=i+2;x<m;++x){
					vr.pb(a[x]);
				}
				dnc(vr);
			}
			break;
		}
	}
	
}

int main(){
	sf("%d",&n);
	for(int i=1;i<=n;++i){
		sf("%d%d",&x,&y);
		v.pb(x,y,0,i);
	}
	for(int i=1;i<=2*n;++i){
		sf("%d%d",&x,&y);
		v.pb(x,y,1,i);
	}
	sort(all(v));
	vii tmp;
	for(int i=0;i<3*n;++i){
		tie(x,y,t,id)=v[i];
		tmp.pb(t,id);
	}
	dnc(tmp);
	for(int i=1;i<=n;++i)pf("%d %d\n",ans[i].fi,ans[i].se);
}

/*
2
1 0
4 0
2 0
3 0
5 0
6 0
*/

Compilation message

laser.cpp: In function 'int main()':
laser.cpp:104:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |  sf("%d",&n);
      |    ^
laser.cpp:106:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |   sf("%d%d",&x,&y);
      |     ^
laser.cpp:110:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |   sf("%d%d",&x,&y);
      |     ^
laser.cpp: In function 'void dnc(vii)':
laser.cpp:46:6: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |  int s;
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -