Submission #11447703
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; using P = pair<int, int>; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; template <int MOD = 1000000007> struct Mint { int x; Mint() : x(0) {} Mint(long long t) { x = t % MOD; if (x < 0) x += MOD; } Mint pow(int n) { Mint res(1), t(x); while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } Mint inv() const { int a = x, b = MOD, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return Mint(u); } Mint &operator+=(Mint a) { x += a.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator-=(Mint a) { x += MOD - a.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator*=(Mint a) { x = int(1LL * x * a.x % MOD); return *this; } Mint &operator/=(Mint a) { return (*this) *= a.inv(); } Mint operator+(Mint a) const { return Mint(x) += a; } Mint operator-(Mint a) const { return Mint(x) -= a; } Mint operator*(Mint a) const { return Mint(x) *= a; } Mint operator/(Mint a) const { return Mint(x) /= a; } Mint operator-() const { return Mint(-x); } bool operator==(const Mint a) { return x == a.x; } bool operator!=(const Mint a) { return x != a.x; } bool operator<(const Mint a) { return x < a.x; } friend ostream &operator<<(ostream &os, const Mint &a) { return os << a.x; } friend istream &operator>>(istream &is, Mint &a) { int t; is >> t; a = Mint<MOD>(t); return (is); } }; bool check(vector<vector<int>> &x) { rep(i, 3) { rep(j, 5) { if ((x[i][j] < x[i + 1][j] && x[i + 1][j] < x[i + 2][j]) || (x[i][j] > x[i + 1][j] && x[i + 1][j] > x[i + 2][j])) return false; } } rep(i, 5) { rep(j, 3) { if ((x[i][j] < x[i][j + 1] && x[i][j + 1] < x[i][j + 2]) || (x[i][j] > x[i][j + 1] && x[i][j + 1] > x[i][j + 2])) return false; } } return true; } signed main() { const int n = 5; bool use[n * n + 1] = {}; vector<P> e; vector<vector<int>> x(n, vector<int>(n)); rep(i, n) { rep(j, n) { cin >> x[i][j]; if (x[i][j] == 0) e.emplace_back(i, j); else use[x[i][j]] = true; } } if (e.size() > 8) return 0; vector<int> v; for (int i = 1; i <= n * n; i++) { if (!use[i]) v.emplace_back(i); } sort(ALL(v)); Mint<> ans = 0; do { rep(i, e.size()) { x[e[i].first][e[i].second] = v[i]; } if (check(x)) ans += 1; } while (next_permutation(ALL(v))); cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 25個の整数 |
User | Dente |
Language | C++14 (GCC 5.4.1) |
Score | 30 |
Code Size | 3400 Byte |
Status | WA |
Exec Time | 4 ms |
Memory | 256 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 | 1 ms | 256 KB |
sample-02.txt | AC | 4 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |
sample-04.txt | AC | 1 ms | 256 KB |
test-1-01.txt | AC | 2 ms | 256 KB |
test-1-02.txt | AC | 1 ms | 256 KB |
test-1-03.txt | AC | 1 ms | 256 KB |
test-1-04.txt | AC | 1 ms | 256 KB |
test-1-05.txt | AC | 1 ms | 256 KB |
test-1-06.txt | AC | 2 ms | 256 KB |
test-1-07.txt | AC | 2 ms | 256 KB |
test-1-08.txt | AC | 2 ms | 256 KB |
test-1-09.txt | AC | 2 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 | 2 ms | 256 KB |
test-1-13.txt | AC | 1 ms | 256 KB |
test-1-14.txt | AC | 2 ms | 256 KB |
test-1-15.txt | AC | 2 ms | 256 KB |
test-2-01.txt | WA | 1 ms | 256 KB |
test-2-02.txt | WA | 1 ms | 256 KB |
test-2-03.txt | WA | 1 ms | 256 KB |
test-2-04.txt | WA | 1 ms | 256 KB |
test-2-05.txt | WA | 1 ms | 256 KB |
test-2-06.txt | WA | 1 ms | 256 KB |
test-2-07.txt | WA | 1 ms | 256 KB |
test-2-08.txt | WA | 1 ms | 256 KB |
test-2-09.txt | WA | 1 ms | 256 KB |
test-2-10.txt | WA | 1 ms | 256 KB |