Submission #9486398


Source Code Expand

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int,int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

vector<int>X, Y;
typedef pair<int, P>PP;
void solve() {
	const int N = 30;
	int A[30][30];
	auto comp = [&,N,A](const PP &p1,const PP &p2) {
		int c1 = p1.first, c2 = p2.first;
		if (c1 != c2)return c1 < c2;
		int x = p1.second.first, y = p1.second.second;
		c1 = 0, c2 = 0;
		REP(k, 4) {
			int nx = x + dx[k], ny = y + dy[k];
			if (nx < 0 || nx >= N || ny < 0 || ny >= N)continue;
			if (A[nx][ny] == 0)continue;
			if (A[nx][ny] == A[x][y]-1) {
				c1++;
			}
		}
		x = p2.second.first, y = p2.second.second;
		REP(k, 4) {
			int nx = x + dx[k], ny = y + dy[k];
			if (nx < 0 || nx >= N || ny < 0 || ny >= N)continue;
			if (A[nx][ny] == 0)continue;
			if (A[nx][ny] == A[x][y]-1) {
				c2++;
			}
		}
		if (c1>0&&c2>0)return c1 > c2;
		else return c1 < c2;
	};
	priority_queue<PP,vector<PP>,decltype(comp)>que(comp);
	REP(i, N) {
		REP(j, N) {
			cin >> A[i][j];
			que.push({ A[i][j],{i,j} });
		}
	}
	ll cnt = 0;
	while (!que.empty()) {
		pair<int, P>p = que.top();
		que.pop();
		int c = p.first, x = p.second.first, y = p.second.second;
		if (A[x][y] != c)continue;
		A[x][y]--;
		cnt++;
		X.push_back(x), Y.push_back(y);
		if (A[x][y] > 0)que.push({ A[x][y],{x,y} });
		bool ok = true;
		while (ok) {
			ok = false;
			REP(k, 4) {
				int nx = x + dx[k], ny = y + dy[k];
				if (nx < 0 || nx >= N || ny < 0 || ny >= N)continue;
				if (A[nx][ny] == 0)continue;
				if (A[nx][ny] == A[x][y]) {
					ok = true;
					x = nx, y = ny;
					A[x][y]--;
					X.push_back(x), Y.push_back(y);
					if (A[x][y] > 0)que.push({ A[x][y],{ x,y } });
					break;
				}
			}
		}
	}
	//print(cnt);
	int M = X.size();
	REP(i, M) {
		pe(X[i] + 1); print(Y[i] + 1);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}


Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User Mojumbo
Language C++14 (GCC 5.4.1)
Score 812836
Code Size 3608 Byte
Status AC
Exec Time 166 ms
Memory 1136 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 81359 / 100000 80967 / 100000 81638 / 100000 80677 / 100000 81260 / 100000 81273 / 100000 81499 / 100000 81513 / 100000 81488 / 100000 81162 / 100000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 150 ms 1008 KB
subtask_01_02.txt AC 158 ms 1136 KB
subtask_01_03.txt AC 152 ms 1136 KB
subtask_01_04.txt AC 166 ms 1136 KB
subtask_01_05.txt AC 152 ms 1136 KB
subtask_01_06.txt AC 153 ms 1008 KB
subtask_01_07.txt AC 156 ms 1096 KB
subtask_01_08.txt AC 150 ms 1008 KB
subtask_01_09.txt AC 156 ms 1136 KB
subtask_01_10.txt AC 157 ms 1096 KB