Submission #1291195


Source Code Expand

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>

using namespace std;
#define MOD 1000000007

bool B[26] = {false};
int T[1 << 25] = {-1};
int mp[26];

int bit(int i) {
    i = (i & 0x55555555) + (i >> 1 & 0x55555555);
    i = (i & 0x33333333) + (i >> 2 & 0x33333333);
    i = (i & 0x0f0f0f0f) + (i >> 4 & 0x0f0f0f0f);
    i = (i & 0x00ff00ff) + (i >> 8 & 0x00ff00ff);
    return (i & 0x0000ffff) + (i >> 16 & 0x0000ffff);
}

bool calc(int state, int i) {
    int pos = 1 << i;
    return (state & pos) > 0;
}

int minu(int state, int i) {
    int pos = 1 << i;
    return state - pos;
}

int dfs(int state) {
    if (T[state] != -1)
        return T[state];
    int c = bit(state);
    if (B[c]) {
        int j = mp[c];
        if (!calc(state, j)) {
            T[state] = 0;
            return 0;
        }
        int x = j % 5;
        int y = j / 5;
        if (0 < x && x < 4 && (calc(state, j + 1) ^ (calc(state, j - 1)))) {
            T[state] = 0;
            return 0;
        }
        if (0 < y && y < 4 && (calc(state, j + 5) ^ (calc(state, j - 5)))) {
            T[state] = 0;
            return 0;
        }
        int res = dfs(minu(state, j));
        T[state] = res;
        return res;
    } else {
        int sum = 0;
        for (int j = 0; j < 25; j++) {
            if (!calc(state, j)) {
                continue;
            }
            int x = j % 5;
            int y = j / 5;
            if (0 < x && x < 4 && (calc(state, j + 1) ^ (calc(state, j - 1)))) {
                continue;
            }
            if (0 < y && y < 4 && (calc(state, j + 5) ^ (calc(state, j - 5)))) {
                continue;
            }
            sum += dfs(minu(state, j));
            sum %= MOD;
        }
        T[state] = sum;
        return sum;
    }
}

int main() {
    for (int i = 0; i < 25; i++) {
        int c;
        cin >> c;
        if (c != 0) {
            B[c] = true;
            mp[c] = i;
        }
    }
    T[0] = 1;
    cout << dfs((1 << 25) - 1) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - 25個の整数
User mban
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2352 Byte
Status CE

Compile Error

g++: internal compiler error: File size limit exceeded (program as)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.