Submission #49801

# Submission time Handle Problem Language Result Execution time Memory
49801 2018-06-03T07:50:40 Z 강태규(#1279, imeimi2000) None (JOI16_solitaire) C++11
10 / 100
9 ms 832 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int mod = 1e9 + 7;
int n;
char grid[3][31];
pii w[100];
int dp[1 << 16];
int xcnt;

bool valid(int x, int y) {
    return 0 <= x & x < 3 && 0 <= y && y < n && grid[x][y] == 'o';
}

int pro_dp(int gd) {
    if (dp[gd] != -1) return dp[gd];
    if (gd == (1 << xcnt) - 1) return dp[gd] = 1;
    dp[gd] = 0;
    for (int i = 0; i < xcnt; ++i) {
        if ((gd | (1 << i)) == gd) continue;
        if (valid(w[i].first + 1, w[i].second)
             && valid(w[i].first - 1, w[i].second)
             || valid(w[i].first, w[i].second + 1)
             && valid(w[i].first, w[i].second - 1)) {
            grid[w[i].first][w[i].second] = 'o';
            dp[gd] = (dp[gd] + pro_dp(gd | (1 << i))) % mod;
            grid[w[i].first][w[i].second] = 'x';
        }
    }
    return dp[gd];
}

int main() {
    scanf("%d", &n);
    if (n > 30) return 0;
    scanf("%s", grid[0]);
    scanf("%s", grid[1]);
    scanf("%s", grid[2]);
    for (int i = 0; i < n; ++i) {
        if (grid[0][i] == 'x') w[xcnt++] = pii(0, i);
        if (grid[1][i] == 'x') w[xcnt++] = pii(1, i);
        if (grid[2][i] == 'x') w[xcnt++] = pii(2, i);
    }
    if (xcnt > 16) return 0;
    for (int i = 0; i < (1 << xcnt); ++i) dp[i] = -1;
    printf("%d\n", pro_dp(0));
	return 0;
}

Compilation message

solitaire.cpp: In function 'bool valid(int, int)':
solitaire.cpp:29:14: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
     return 0 <= x & x < 3 && 0 <= y && y < n && grid[x][y] == 'o';
            ~~^~~~
solitaire.cpp: In function 'int pro_dp(int)':
solitaire.cpp:39:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if (valid(w[i].first + 1, w[i].second)
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              && valid(w[i].first - 1, w[i].second)
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
solitaire.cpp: In function 'int main()':
solitaire.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
solitaire.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", grid[0]);
     ~~~~~^~~~~~~~~~~~~~~
solitaire.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", grid[1]);
     ~~~~~^~~~~~~~~~~~~~~
solitaire.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", grid[2]);
     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 576 KB Output is correct
5 Correct 9 ms 704 KB Output is correct
6 Correct 8 ms 756 KB Output is correct
7 Correct 5 ms 756 KB Output is correct
8 Correct 5 ms 816 KB Output is correct
9 Correct 6 ms 832 KB Output is correct
10 Correct 7 ms 832 KB Output is correct
11 Correct 6 ms 832 KB Output is correct
12 Correct 5 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 576 KB Output is correct
5 Correct 9 ms 704 KB Output is correct
6 Correct 8 ms 756 KB Output is correct
7 Correct 5 ms 756 KB Output is correct
8 Correct 5 ms 816 KB Output is correct
9 Correct 6 ms 832 KB Output is correct
10 Correct 7 ms 832 KB Output is correct
11 Correct 6 ms 832 KB Output is correct
12 Correct 5 ms 832 KB Output is correct
13 Incorrect 2 ms 832 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 576 KB Output is correct
5 Correct 9 ms 704 KB Output is correct
6 Correct 8 ms 756 KB Output is correct
7 Correct 5 ms 756 KB Output is correct
8 Correct 5 ms 816 KB Output is correct
9 Correct 6 ms 832 KB Output is correct
10 Correct 7 ms 832 KB Output is correct
11 Correct 6 ms 832 KB Output is correct
12 Correct 5 ms 832 KB Output is correct
13 Incorrect 2 ms 832 KB Output isn't correct
14 Halted 0 ms 0 KB -