結果

問題 No.1598 4×4 Grid
ユーザー chocoruskchocorusk
提出日時 2021-07-09 22:59:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 548 ms / 4,000 ms
コード長 1,447 bytes
コンパイル時間 3,386 ms
コンパイル使用メモリ 186,932 KB
実行使用メモリ 95,152 KB
最終ジャッジ日時 2023-09-14 10:32:18
合計ジャッジ時間 7,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
13,916 KB
testcase_01 AC 293 ms
63,644 KB
testcase_02 AC 303 ms
65,548 KB
testcase_03 AC 418 ms
90,272 KB
testcase_04 AC 473 ms
93,864 KB
testcase_05 AC 532 ms
95,112 KB
testcase_06 AC 548 ms
95,152 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 299 ms
64,604 KB
testcase_09 AC 485 ms
94,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
ll dp[216*2+1][1<<16];
int main()
{
    int K; cin>>K;
    int n=16, d=4;
    dp[K][0]=1;
    int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
    for(int i=0; i<(1<<n); i++){
        int p=popcount(i);
        for(int j=0; j<n; j++){
            if(i&(1<<j)) continue;
            int x=(j>>2), y=(j&3), t=0;
            for(int k=0; k<4; k++){
                int x1=x+dx[k], y1=y+dy[k];
                if(x1<0 || x1>=d || y1<0 || y1>=d) continue;
                int j1=((x1<<2)^y1);
                if(i&(1<<j1)) t++;
                else t--;
            }
            for(int k=0; k<=2*K; k++){
                if(!dp[k][i]) continue;
                int k1=k+p*t;
                if(k1>=0 && k1<=2*K){
                    dp[k1][i^(1<<j)]+=dp[k][i];
                }
            }
        }
    }
    cout<<dp[2*K][(1<<n)-1]<<endl;
    return 0;
}
0