Submission #434396
Source Code Expand
#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()
inline int scani() { int n; scanf("%d", &n); return n; }
static ll const MOD = 1000000007;
static int const INF = 1<<29;
using pii = pair<int,int>;
array<int, 5*5> board;
array<pii, 5*3> cons[2]; //[0] 横制約, [1] 縦制約
bool monotone(array<int, 3> const& ns) {
return (ns[0] < ns[1] && ns[1] < ns[2])
|| (ns[2] < ns[1] && ns[1] < ns[0]);
}
bool verify(vector<int> const& perm) {
array<int, 5*5> bs = board;
int k = 0;
rep(i, 5) rep(j, 5) {
if ( bs[i * 5 + j] == 0 ) bs[i * 5 + j] = perm[k++];
}
array<int, 3> ns;
rep(i, 3) rep(j, 5) {
rep(l, 3) ns[l] = bs[(i + l) * 5 + j];
if ( monotone(ns) ) return false;
}
rep(i, 5) rep(j, 3) {
rep(l, 3) ns[l] = bs[i * 5 + (j + l)];
if ( monotone(ns) ) return false;
}
return true;
}
signed main() {
rep(i, 5) rep(j, 5) {
cin >> board[i * 5 + j];
}
set<int> nums;
rep(i, 25) {
nums.insert(i + 1);
}
rep(i, 5 * 5) {
nums.erase(board[i]);
}
if ( nums.size() < 9 ) {
vector<int> perm(all(nums));
int comb = 0;
do {
if ( verify(perm) ) comb++;
} while ( next_permutation(all(perm)) );
cout << comb << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - 25個の整数 |
User |
vain0 |
Language |
C++11 (GCC 4.9.2) |
Score |
30 |
Code Size |
1943 Byte |
Status |
WA |
Exec Time |
36 ms |
Memory |
928 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
30 / 30 |
0 / 70 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 |
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 |
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 |
Case Name |
Status |
Exec Time |
Memory |
sample-01.txt |
AC |
25 ms |
924 KB |
sample-02.txt |
AC |
36 ms |
920 KB |
sample-03.txt |
AC |
24 ms |
924 KB |
sample-04.txt |
AC |
23 ms |
924 KB |
test-1-01.txt |
AC |
26 ms |
928 KB |
test-1-02.txt |
AC |
23 ms |
744 KB |
test-1-03.txt |
AC |
23 ms |
928 KB |
test-1-04.txt |
AC |
24 ms |
928 KB |
test-1-05.txt |
AC |
28 ms |
796 KB |
test-1-06.txt |
AC |
27 ms |
800 KB |
test-1-07.txt |
AC |
28 ms |
800 KB |
test-1-08.txt |
AC |
28 ms |
800 KB |
test-1-09.txt |
AC |
26 ms |
924 KB |
test-1-10.txt |
AC |
24 ms |
796 KB |
test-1-11.txt |
AC |
22 ms |
924 KB |
test-1-12.txt |
AC |
28 ms |
800 KB |
test-1-13.txt |
AC |
25 ms |
796 KB |
test-1-14.txt |
AC |
28 ms |
796 KB |
test-1-15.txt |
AC |
29 ms |
736 KB |
test-2-01.txt |
WA |
23 ms |
796 KB |
test-2-02.txt |
WA |
25 ms |
924 KB |
test-2-03.txt |
WA |
23 ms |
748 KB |
test-2-04.txt |
WA |
24 ms |
924 KB |
test-2-05.txt |
WA |
24 ms |
928 KB |
test-2-06.txt |
WA |
26 ms |
800 KB |
test-2-07.txt |
WA |
24 ms |
796 KB |
test-2-08.txt |
WA |
24 ms |
800 KB |
test-2-09.txt |
WA |
25 ms |
800 KB |
test-2-10.txt |
WA |
25 ms |
804 KB |