提出 #577969


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
  return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
  s<<"[ ";
  for (auto it : c) s << it << " ";
  s<<"]";
  return s;
}
// Let's Fight!

const int MAXN = 20202;

struct Point
{
	int x;
	int y;
	int z;

	bool operator<(const Point &p) const
	{
		return tie(x, y, z) < tie(p.x, p.y, p.z);
	}
};

struct Edge
{
	Point p[2];

	bool operator<(const Edge &e) const
	{
		return tie(p[0], p[1]) < tie(e.p[0], e.p[1]);
	}
};

struct Face
{
	Point p[2];

	bool operator<(const Face &f) const
	{
		return tie(p[0], p[1]) < tie(f.p[0], f.p[1]);
	}
};

int A, B, C, N, PP;

set<Point> pts;
set<Edge> edges;
set<Face> faces;
map<Point, int> mp;
vector<int> el[1010101];
bool vis[1010101];

void init()
{
	pts.clear();
	edges.clear();
	faces.clear();
	mp.clear();
}

void make_point(Point p)
{
	int x = p.x, y = p.y, z = p.z;

	vector<Point> vec;
	vec.PB({x, y, z});
	vec.PB({x, y, z+1});
	vec.PB({x, y+1, z});
	vec.PB({x, y+1, z+1});
	vec.PB({x+1, y, z});
	vec.PB({x+1, y, z+1});
	vec.PB({x+1, y+1, z});
	vec.PB({x+1, y+1, z+1});

	for(auto v: vec)
		pts.insert(v);

	edges.insert({vec[0], vec[1]});
	edges.insert({vec[2], vec[3]});
	edges.insert({vec[4], vec[5]});
	edges.insert({vec[6], vec[7]});
	edges.insert({vec[0], vec[2]});
	edges.insert({vec[1], vec[3]});
	edges.insert({vec[4], vec[6]});
	edges.insert({vec[5], vec[7]});
	edges.insert({vec[0], vec[4]});
	edges.insert({vec[1], vec[5]});
	edges.insert({vec[2], vec[6]});
	edges.insert({vec[3], vec[7]});

	faces.insert({vec[0], vec[3]});
	faces.insert({vec[4], vec[7]});
	faces.insert({vec[0], vec[5]});
	faces.insert({vec[2], vec[7]});
	faces.insert({vec[0], vec[6]});
	faces.insert({vec[1], vec[7]});
}

bool inrange(int xl, int xr, int yl, int yr, int zl, int zr, Point p)
{
	return xl <= p.x && p.x <= xr && yl <= p.y && p.y <= yr && zl <= p.z && p.z <= zr;
}

int calcE(int xl, int xr, int yl, int yr, int zl, int zr, int &cure)
{
	for(auto e: edges)
	{
		if(!inrange(xl, xr, yl, yr, zl, zr, e.p[0])) continue;
		if(!inrange(xl, xr, yl, yr, zl, zr, e.p[1])) continue;
		cure++;
	}

	int vs = 0;
	vector<Point> vec;
	for(auto p: pts)
	{
		if(!inrange(xl, xr, yl, yr, zl, zr, p)) continue;
		vec.PB(p);
		vs++;
	}

	for(auto v: vec)
	{
		int a = mp[vec[0]];
		int b = mp[v];
		if(a == b) continue;
		el[a].PB(b);
		el[b].PB(a);
	}

	return vs - 1;
}

int calcF(int xl, int xr, int yl, int yr, int zl, int zr, int &curf)
{
	int vs = 0;
	vector<Point> vec;
	for(auto p: pts)
	{
		if(!inrange(xl, xr, yl, yr, zl, zr, p)) continue;
		vec.PB(p);
		vs++;
	}

	int es = 0;
	for(auto e: edges)
	{
		if(!inrange(xl, xr, yl, yr, zl, zr, e.p[0])) continue;
		if(!inrange(xl, xr, yl, yr, zl, zr, e.p[1])) continue;
		es++;
	}

	for(auto f: faces)
	{
		if(!inrange(xl, xr, yl, yr, zl, zr, f.p[0])) continue;
		if(!inrange(xl, xr, yl, yr, zl, zr, f.p[1])) continue;
		curf++;
	}

	for(auto v: vec)
	{
		int a = mp[vec[0]];
		int b = mp[v];
		if(a == b) continue;
		el[a].PB(b);
		el[b].PB(a);
	}

	return es - vs + 1;
}

void dfs(int v)
{
	if(vis[v]) return;
	vis[v] = true;
	for(auto e: el[v])
		dfs(e);
}

int calc()
{
	int V = pts.size();
	int E = 0;
	int cure = 0;

	vector<int> nume;

	nume.PB(calcE(0, 0, 0, 0, 0, C, cure));
	nume.PB(calcE(0, 0, B, B, 0, C, cure));
	nume.PB(calcE(A, A, 0, 0, 0, C, cure));
	nume.PB(calcE(A, A, B, B, 0, C, cure));

	nume.PB(calcE(0, 0, 0, B, 0, 0, cure));
	nume.PB(calcE(0, 0, 0, B, C, C, cure));
	nume.PB(calcE(A, A, 0, B, 0, 0, cure));
	nume.PB(calcE(A, A, 0, B, C, C, cure));

	nume.PB(calcE(0, A, 0, 0, 0, 0, cure));
	nume.PB(calcE(0, A, 0, 0, C, C, cure));
	nume.PB(calcE(0, A, B, B, 0, 0, cure));
	nume.PB(calcE(0, A, B, B, C, C, cure));

	E += edges.size() - cure;
	for(auto x: nume)
		E += x;

	int F = 0;
	int curf = 0;

	vector<int> numf;

	numf.PB(calcF(0, 0, 0, B, 0, C, curf));
	numf.PB(calcF(A, A, 0, B, 0, C, curf));
	numf.PB(calcF(0, A, 0, 0, 0, C, curf));
	numf.PB(calcF(0, A, B, B, 0, C, curf));
	numf.PB(calcF(0, A, 0, B, 0, 0, curf));
	numf.PB(calcF(0, A, 0, B, C, C, curf));

	F += faces.size() - curf;
	for(auto x: numf)
		F += x;

	//cout<<"CURF "<<curf<<endl;

	for(auto e: nume)
		F += 2 * e;
	F -= 2 * cure;

	int conn = 0;

	for(int i=0; i<PP; i++)
	{
		if(vis[i]) continue;
		dfs(i);
		conn++;
	}

	//cout<<"V "<<V<<" E "<<E<<" F "<<F<<endl;

	return V - E + F - conn - N;
}

int main() {
    IOS;

	while(cin>>A>>B>>C>>N)
	{
		init();
		pts.insert({0, 0, 0});
		pts.insert({0, 0, C});
		pts.insert({0, B, 0});
		pts.insert({0, B, C});
		pts.insert({A, 0, 0});
		pts.insert({A, 0, C});
		pts.insert({A, B, 0});
		pts.insert({A, B, C});
		for(int i=0; i<N; i++)
		{
			Point p;
			cin>>p.x>>p.y>>p.z;
			make_point(p);
		}

		int cnt = 0;
		for(auto p: pts)
		{
			mp[p] = cnt++;
		}
		PP = cnt;
		for(int i=0; i<PP; i++)
		{
			el[i].clear();
			vis[i] = false;
		}
		for(auto e: edges)
		{
			int a = mp[e.p[0]];
			int b = mp[e.p[1]];
			el[a].PB(b);
			el[b].PB(a);
		}

		int ans = calc();
		cout<<ans<<endl;
	}

    return 0;
}

提出情報

提出日時
問題 G - Cube Dividing
ユーザ bcw0x1bd2
言語 C++11 (GCC 4.8.1)
得点 0
コード長 5695 Byte
結果 WA
実行時間 1661 ms
メモリ 81392 KiB

ジャッジ結果

セット名 All
得点 / 配点 0 / 100
結果
AC × 41
WA × 25
セット名 テストケース
All 00_sample_00, 00_sample_01, 00_sample_02, 10_random_small_00, 10_random_small_01, 10_random_small_02, 10_random_small_03, 10_random_small_04, 10_random_small_05, 10_random_small_06, 10_random_small_07, 10_random_small_08, 10_random_small_09, 11_random_large_00, 11_random_large_01, 11_random_large_02, 11_random_large_03, 11_random_large_04, 20_sparse_00, 20_sparse_01, 20_sparse_02, 20_sparse_03, 20_sparse_04, 20_sparse_05, 20_sparse_06, 20_sparse_07, 20_sparse_08, 20_sparse_09, 30_path_00, 30_path_01, 30_path_02, 30_path_03, 30_path_04, 30_path_05, 30_path_06, 30_path_07, 30_path_08, 30_path_09, 31_permutation_00, 31_permutation_01, 31_permutation_02, 31_permutation_03, 31_permutation_04, 40_largest_00, 40_largest_01, 41_smallest_00, 41_smallest_01, 41_smallest_02, 41_smallest_03, 41_smallest_04, 50_max_00, 50_max_01, 60_hirabettai_00, 60_hirabettai_01, 60_hirabettai_02, 60_hirabettai_03, 60_hirabettai_04, 61_hosonagai_00, 61_hosonagai_01, 61_hosonagai_02, 61_hosonagai_03, 61_hosonagai_04, 70_compress_killer_00, 70_compress_killer_01, 80_zero_00, 80_zero_01
ケース名 結果 実行時間 メモリ
00_sample_00 AC 95 ms 24772 KiB
00_sample_01 AC 77 ms 24832 KiB
00_sample_02 AC 79 ms 24772 KiB
10_random_small_00 WA 341 ms 37572 KiB
10_random_small_01 WA 368 ms 40248 KiB
10_random_small_02 WA 431 ms 38968 KiB
10_random_small_03 WA 503 ms 45380 KiB
10_random_small_04 WA 1017 ms 59520 KiB
10_random_small_05 WA 1025 ms 59576 KiB
10_random_small_06 WA 479 ms 42172 KiB
10_random_small_07 WA 431 ms 41584 KiB
10_random_small_08 WA 199 ms 31812 KiB
10_random_small_09 WA 343 ms 38532 KiB
11_random_large_00 AC 804 ms 57284 KiB
11_random_large_01 AC 1175 ms 66436 KiB
11_random_large_02 AC 1313 ms 69756 KiB
11_random_large_03 AC 456 ms 46596 KiB
11_random_large_04 AC 109 ms 27084 KiB
20_sparse_00 AC 362 ms 42216 KiB
20_sparse_01 AC 438 ms 38860 KiB
20_sparse_02 AC 462 ms 46596 KiB
20_sparse_03 AC 429 ms 40676 KiB
20_sparse_04 AC 230 ms 33840 KiB
20_sparse_05 AC 301 ms 36560 KiB
20_sparse_06 AC 199 ms 31428 KiB
20_sparse_07 AC 305 ms 34096 KiB
20_sparse_08 AC 332 ms 39984 KiB
20_sparse_09 AC 203 ms 30908 KiB
30_path_00 WA 210 ms 32828 KiB
30_path_01 WA 90 ms 25292 KiB
30_path_02 WA 87 ms 25600 KiB
30_path_03 WA 191 ms 30648 KiB
30_path_04 WA 94 ms 25980 KiB
30_path_05 WA 167 ms 29700 KiB
30_path_06 WA 94 ms 25988 KiB
30_path_07 WA 94 ms 25784 KiB
30_path_08 WA 78 ms 24960 KiB
30_path_09 WA 138 ms 28084 KiB
31_permutation_00 AC 1433 ms 72376 KiB
31_permutation_01 AC 1306 ms 68420 KiB
31_permutation_02 AC 1217 ms 65968 KiB
31_permutation_03 AC 1084 ms 63172 KiB
31_permutation_04 AC 568 ms 49732 KiB
40_largest_00 AC 1433 ms 72444 KiB
40_largest_01 AC 1425 ms 72380 KiB
41_smallest_00 AC 75 ms 24832 KiB
41_smallest_01 AC 77 ms 24760 KiB
41_smallest_02 AC 77 ms 24756 KiB
41_smallest_03 AC 77 ms 24840 KiB
41_smallest_04 AC 77 ms 24828 KiB
50_max_00 AC 1661 ms 81392 KiB
50_max_01 AC 565 ms 49276 KiB
60_hirabettai_00 WA 1129 ms 65204 KiB
60_hirabettai_01 WA 701 ms 52480 KiB
60_hirabettai_02 WA 94 ms 26116 KiB
60_hirabettai_03 WA 616 ms 49536 KiB
60_hirabettai_04 WA 467 ms 44120 KiB
61_hosonagai_00 AC 77 ms 24780 KiB
61_hosonagai_01 AC 80 ms 25012 KiB
61_hosonagai_02 AC 195 ms 32724 KiB
61_hosonagai_03 AC 1445 ms 74960 KiB
61_hosonagai_04 AC 78 ms 24832 KiB
70_compress_killer_00 AC 362 ms 42304 KiB
70_compress_killer_01 AC 1304 ms 70172 KiB
80_zero_00 AC 77 ms 24760 KiB
80_zero_01 AC 76 ms 24760 KiB