AtCoder Beginner Contest 025

Submission #3981123

Source codeソースコード

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int x[5][5];
bool used[26];

void numSet(vector<int> pos, vector<int> num){
	int n = (int)pos.size();
	rep (i, n){
		int row = pos[i] / 5;
		int col = pos[i] % 5;
		x[row][col] = num[i];
	} // end rep
}

void reStore(vector<int> pos){
	int n = (int)pos.size();
	rep (i, n){
		int row = pos[i] / 5;
		int col = pos[i] % 5;
		x[row][col] = 0;
	} // end rep
}

bool is_ok(void){
	rep (i, 5){
		rep (j, 5){
			if (i + 2 < 5){
				if (x[i][j] < x[i+1][j] && x[i+1][j] < x[i+2][j]){
					return false;
				} // end if
				if (x[i][j] > x[i+1][j] && x[i+1][j] > x[i+2][j]){
					return false;
				} // end if
			} // end if
			if (j + 2 < 5){
				if (x[i][j] < x[i][j+1] && x[i][j+1] < x[i][j+2]){
					return false;
				} // end if
				if (x[i][j] > x[i][j+1] && x[i][j+1] > x[i][j+2]){
					return false;
				} // end if
			} // end if
		} // end rep
	} // end rep
	return true;
}	

void dispX(void){
	rep (i, 5){
		rep (j, 5){
			cerr << setw(2) << x[i][j];
		} // end rep
		cerr << endl;
	} // end rep
}

int main()
{
	memset(used, false, sizeof(used));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	rep (i, 5) rep (j, 5) cin >> x[i][j], used[x[i][j]] |= true;

	vector<int> unSetPos; unSetPos.clear();
	vector<int> unSetNum; unSetNum.clear();
	rep (i, 5) rep (j, 5){
		if (x[i][j] == 0){
			unSetPos.push_back(i * 5 + j);
		} // end if
		int curr = (i * 5 + j + 1);
		if (!used[curr]){
			unSetNum.push_back(curr);
		} // end if
	} // end rep

	if ((int)unSetNum.size() > 8){
		exit(-1);
	} // end if

/*
	rep (i, (int)unSetNum.size()){
		cerr << setw(2) << unSetNum[i] << ' ';
	} // end rep
	cerr << endl;
*/

	int res = 0;
	do{
		numSet(unSetPos, unSetNum);
		if (is_ok()){
			++res;
//			dispX();
//			cerr << endl;
		} // end if
		reStore(unSetPos);
	}while(next_permutation(ALL(unSetNum)));

	cout << res << endl;

	return 0;
}

Submission

Task問題 D - 25個の整数
User nameユーザ名 ty70
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 30
Source lengthソースコード長 2131 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt
Subtask1 30 / 30 sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt,test-1-01.txt,test-1-02.txt,test-1-03.txt,test-1-04.txt,test-1-05.txt,test-1-06.txt,test-1-07.txt,test-1-08.txt,test-1-09.txt,test-1-10.txt,test-1-11.txt,test-1-12.txt,test-1-13.txt,test-1-14.txt,test-1-15.txt
Subtask2 0 / 70 sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt,test-1-01.txt,test-1-02.txt,test-1-03.txt,test-1-04.txt,test-1-05.txt,test-1-06.txt,test-1-07.txt,test-1-08.txt,test-1-09.txt,test-1-10.txt,test-1-11.txt,test-1-12.txt,test-1-13.txt,test-1-14.txt,test-1-15.txt,test-2-01.txt,test-2-02.txt,test-2-03.txt,test-2-04.txt,test-2-05.txt,test-2-06.txt,test-2-07.txt,test-2-08.txt,test-2-09.txt,test-2-10.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 64 ms 256 KB
sample-03.txt AC 2 ms 256 KB
sample-04.txt AC 1 ms 256 KB
test-1-01.txt AC 62 ms 256 KB
test-1-02.txt AC 2 ms 256 KB
test-1-03.txt AC 2 ms 256 KB
test-1-04.txt AC 9 ms 256 KB
test-1-05.txt AC 9 ms 256 KB
test-1-06.txt AC 61 ms 256 KB
test-1-07.txt AC 62 ms 256 KB
test-1-08.txt AC 61 ms 256 KB
test-1-09.txt AC 61 ms 256 KB
test-1-10.txt AC 1 ms 256 KB
test-1-11.txt AC 1 ms 256 KB
test-1-12.txt AC 60 ms 256 KB
test-1-13.txt AC 1 ms 256 KB
test-1-14.txt AC 62 ms 256 KB
test-1-15.txt AC 60 ms 256 KB
test-2-01.txt RE
test-2-02.txt RE
test-2-03.txt RE
test-2-04.txt RE
test-2-05.txt RE
test-2-06.txt RE
test-2-07.txt RE
test-2-08.txt RE
test-2-09.txt RE
test-2-10.txt RE