CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1004303

Source codeソースコード

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=1010;
int n,a[N],s;
VI d;
PII cmp(PII a,PII b) {
	if (a.fi==b.fi) return mp(0,a.se<b.se?1:-1);
	else if (a.se==b.se) return mp(a.fi<b.fi?1:-1,0);
	else assert(0);
}
vector<PII> generate(VI x) {
	if (SZ(x)==4) {
		return vector<PII>{mp(0,0),mp(1,0),mp(1,1),mp(0,1)};
	} else {
		int m=SZ(x),p=-1;
		vector<PII> c,cc;
		rep(i,0,m) if (x[i]==90&&x[(i+1)%m]==270&&x[(i+2)%m]==90) {
			VI y; rep(j,0,m-2) y.pb(x[(i+2+j)%m]);
			c=generate(y);
			p=i; break;
		}
		if (p>=0) {
			for (auto &q:c) q.fi*=2,q.se*=2;
			PII v=c[0];
			PII d1=cmp(c[0],c[m-3]),d2=cmp(c[0],c[1]);
			c.insert(c.begin(),v);
			c.insert(c.begin(),v);
			c[0].fi+=d1.fi; c[0].se+=d1.se;
			c[1].fi+=d1.fi+d2.fi; c[1].se+=d1.se+d2.se;
			c[2].fi+=d2.fi; c[2].se+=d2.se;
			d.clear();
			for (auto q:c) d.pb(q.fi); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.fi=lower_bound(all(d),q.fi)-d.begin();
			d.clear();
			for (auto q:c) d.pb(q.se); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.se=lower_bound(all(d),q.se)-d.begin();
			rep(j,0,m) cc.pb(c[(m-p+j)%m]);
//			for (auto p:x) printf("%d ",p); puts("");
//			for (auto p:cc) printf("%d %d\n",p.fi,p.se); puts("");
			return cc;
		}
		rep(i,0,m) if (x[i]==90&&x[(i+1)%m]==270&&x[(i+2)%m]==270) {
			VI y; rep(j,0,m-2) y.pb(x[(i+2+j)%m]);
			c=generate(y);
			p=i; break;
		}
		if (p>=0) {
			for (auto &q:c) q.fi*=2,q.se*=2;
			PII v=c[0];
			PII d1=cmp(c[0],c[m-3]),d2=cmp(c[1],c[0]);
			c.insert(c.begin(),v);
			c.insert(c.begin(),v);
			c[0].fi+=d1.fi; c[0].se+=d1.se;
			c[1].fi+=d1.fi+d2.fi; c[1].se+=d1.se+d2.se;
			c[2].fi+=d2.fi; c[2].se+=d2.se;
			d.clear();
			for (auto q:c) d.pb(q.fi); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.fi=lower_bound(all(d),q.fi)-d.begin();
			d.clear();
			for (auto q:c) d.pb(q.se); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.se=lower_bound(all(d),q.se)-d.begin();
			rep(j,0,m) cc.pb(c[(m-p+j)%m]);
//			for (auto p:x) printf("%d ",p); puts("");
//			for (auto p:cc) printf("%d %d\n",p.fi,p.se); puts("");
			return cc;
		}
		assert(0);
	}
}
int main() {
	scanf("%d",&n);
/*	n=10;
	rep(i,0,n/2+2) a[i]=90;
	rep(i,n/2+2,n) a[i]=270;
	random_shuffle(a,a+n);*/
	rep(i,0,n) {
		scanf("%d",a+i);
//		printf("%d ",a[i]);
		s+=a[i];
	}
	puts("");
	if (s!=180*(n-2)) {
		puts("-1");
		return 0;
	}
	vector<PII> c=generate(VI(a,a+n));
	for (auto p:c) printf("%d %d\n",p.fi,p.se);
}

Submission

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

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:90:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:96:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",a+i);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 1500 / 1500 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,012.txt,013.txt,014.txt,015.txt,016.txt,017.txt,018.txt,019.txt,020.txt,021.txt,022.txt,023.txt,024.txt,025.txt,026.txt,027.txt,028.txt,029.txt,030.txt,031.txt,032.txt,033.txt,034.txt,035.txt,036.txt,037.txt,038.txt,039.txt,040.txt,041.txt,042.txt,043.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 2 ms 256 KB
001.txt AC 2 ms 256 KB
002.txt AC 2 ms 256 KB
003.txt AC 18 ms 1408 KB
004.txt AC 5 ms 512 KB
005.txt AC 8 ms 640 KB
006.txt AC 13 ms 1024 KB
007.txt AC 6 ms 512 KB
008.txt AC 3 ms 384 KB
009.txt AC 7 ms 640 KB
010.txt AC 25 ms 1792 KB
011.txt AC 3 ms 256 KB
012.txt AC 11 ms 896 KB
013.txt AC 11 ms 896 KB
014.txt AC 3 ms 256 KB
015.txt AC 5 ms 384 KB
016.txt AC 16 ms 1152 KB
017.txt AC 2 ms 256 KB
018.txt AC 13 ms 896 KB
019.txt AC 6 ms 512 KB
020.txt AC 37 ms 2432 KB
021.txt AC 2 ms 256 KB
022.txt AC 32 ms 2304 KB
023.txt AC 37 ms 2688 KB
024.txt AC 36 ms 2688 KB
025.txt AC 38 ms 2688 KB
026.txt AC 40 ms 2688 KB
027.txt AC 40 ms 2688 KB
028.txt AC 41 ms 2688 KB
029.txt AC 39 ms 2688 KB
030.txt AC 41 ms 2688 KB
031.txt AC 41 ms 2688 KB
032.txt AC 42 ms 2688 KB
033.txt AC 42 ms 2688 KB
034.txt AC 42 ms 2688 KB
035.txt AC 42 ms 2688 KB
036.txt AC 42 ms 2688 KB
037.txt AC 42 ms 2688 KB
038.txt AC 42 ms 2688 KB
039.txt AC 42 ms 2688 KB
040.txt AC 41 ms 2688 KB
041.txt AC 40 ms 2688 KB
042.txt AC 43 ms 2688 KB
043.txt AC 2 ms 256 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 2 ms 256 KB