Submission #433924
Source Code Expand
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define FOREQ(i,a,b) for(int i = a; i <= (int)b; i++)
#define FOREACH(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) (c).size()
template <class T> void pp(T v) { FOREACH(it, v) cout << *it << ' '; cout << endl ; }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef complex<double> P;
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned uint;
const int INF = 1<<28;
const double EPS = 1.0e-9;
static const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
#undef MOD_CALC
#ifdef MOD_CALC
const ll MOD = 1000 * 1000 * 1000 + 7 ; // 1000000007
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) % MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) % MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) % MOD;}
#endif
int brd[5][5];
vector<pint> rem_pos;
vector<int> rem_num;
vector<bool> used;
int num = 0;
bool brd_check() {
REP(h,3) REP(w,5) {
if(brd[h][w] < brd[h+1][w] && brd[h+1][w] < brd[h+2][w]) return false;
if(brd[h][w] > brd[h+1][w] && brd[h+1][w] > brd[h+2][w]) return false;
}
REP(w,3) REP(h,5) {
if(brd[h][w] < brd[h][w+1] && brd[h][w+1] < brd[h][w+2]) return false;
if(brd[h][w] > brd[h][w+1] && brd[h][w+1] > brd[h][w+2]) return false;
}
return true;
}
int dfs(const int depth) {
int ans = 0;
if(depth == num) {
if(brd_check()) ans++;
return ans;
}
REP(i, num) {
if(used[i] == false) {
used[i] = true;
brd[rem_pos[depth].first][rem_pos[depth].second] = rem_num[i];
ans += dfs(depth+1);
brd[rem_pos[depth].first][rem_pos[depth].second] = 0;
used[i] = false;
}
}
return ans;
}
int main(void)
{
vector<int> exist(5*5+1, 0);
REP(i,5) REP(j,5) {
cin>>brd[i][j];
if(brd[i][j] == 0) {
rem_pos.push_back(make_pair(i, j));
} else {
exist[brd[i][j]] = 1;
}
}
for(int i = 1; i <= 25; i++) {
if(exist[i] == 0) rem_num.push_back(i);
}
//cout << rem_num.size() << endl;
//cout << rem_pos.size() << endl;
num = rem_pos.size();
if(num > 8) {
cout << 0 << endl;
return 0;
}
used = vector<bool>(num, false);
int ans = dfs(0);
//cout << "Answer=";
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - 25個の整数 |
User |
kmatsunaga |
Language |
C++ (GCC 4.9.2) |
Score |
30 |
Code Size |
3404 Byte |
Status |
WA |
Exec Time |
29 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 |
23 ms |
796 KB |
sample-02.txt |
AC |
29 ms |
928 KB |
sample-03.txt |
AC |
22 ms |
804 KB |
sample-04.txt |
AC |
22 ms |
800 KB |
test-1-01.txt |
AC |
26 ms |
808 KB |
test-1-02.txt |
AC |
22 ms |
924 KB |
test-1-03.txt |
AC |
23 ms |
928 KB |
test-1-04.txt |
AC |
23 ms |
920 KB |
test-1-05.txt |
AC |
23 ms |
800 KB |
test-1-06.txt |
AC |
27 ms |
800 KB |
test-1-07.txt |
AC |
26 ms |
924 KB |
test-1-08.txt |
AC |
27 ms |
800 KB |
test-1-09.txt |
AC |
26 ms |
864 KB |
test-1-10.txt |
AC |
24 ms |
804 KB |
test-1-11.txt |
AC |
24 ms |
676 KB |
test-1-12.txt |
AC |
27 ms |
924 KB |
test-1-13.txt |
AC |
22 ms |
928 KB |
test-1-14.txt |
AC |
29 ms |
804 KB |
test-1-15.txt |
AC |
27 ms |
800 KB |
test-2-01.txt |
WA |
22 ms |
920 KB |
test-2-02.txt |
WA |
24 ms |
804 KB |
test-2-03.txt |
WA |
22 ms |
920 KB |
test-2-04.txt |
WA |
24 ms |
928 KB |
test-2-05.txt |
WA |
24 ms |
924 KB |
test-2-06.txt |
WA |
24 ms |
800 KB |
test-2-07.txt |
WA |
22 ms |
804 KB |
test-2-08.txt |
WA |
24 ms |
804 KB |
test-2-09.txt |
WA |
22 ms |
800 KB |
test-2-10.txt |
WA |
22 ms |
804 KB |