結果

問題 No.1598 4×4 Grid
ユーザー Ryushi-techRyushi-tech
提出日時 2021-08-01 09:46:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 4,000 ms
コード長 1,968 bytes
コンパイル時間 4,609 ms
コンパイル使用メモリ 198,244 KB
実行使用メモリ 316,660 KB
最終ジャッジ日時 2023-10-14 18:42:04
合計ジャッジ時間 7,149 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 463 ms
316,408 KB
testcase_01 AC 515 ms
316,408 KB
testcase_02 AC 512 ms
316,652 KB
testcase_03 AC 513 ms
316,396 KB
testcase_04 AC 512 ms
316,660 KB
testcase_05 AC 515 ms
316,608 KB
testcase_06 AC 513 ms
316,464 KB
testcase_07 AC 512 ms
316,536 KB
testcase_08 AC 514 ms
316,540 KB
testcase_09 AC 512 ms
316,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define cnts(x,c) count(all(x),c)
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) {a = b; return 1;} return 0;}
template<class T> void print(const T &t) {cout<<t<<"\n";}
template<class T> void PRINT(const T &t) {rep(i,sz(t)) cout<<t[i]<<" \n"[i==sz(t)-1];}
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

int K;
ll dp[1<<16][1000];

int bit_count(int x) {
    if (x == 0) return 0;
    return bit_count(x >> 1) + (x & 1);
}

int main() {
    fio(); cin>>K;
    dp[0][500]=1;
    rep(mask,1<<16){
        int k=bit_count(mask);
        rep(j,1000) if(dp[mask][j]){
            rep(h,4) rep(w,4) if((mask&(1<<(h*4+w)))==0){
                int tar=j;
                if(h){
                    if((mask&(1<<((h-1)*4+w)))==0) tar-=k;
                    else tar+=k;
                }
                if(h<3){
                    if((mask&(1<<((h+1)*4+w)))==0) tar-=k;
                    else tar+=k;
                }
                if(w){
                    if((mask&(1<<(h*4+w-1)))==0) tar-=k;
                    else tar+=k;
                }
                if(w<3){
                    if((mask&(1<<(h*4+w+1)))==0) tar-=k;
                    else tar+=k;
                }
                dp[mask^(1<<(h*4+w))][tar]+=dp[mask][j];
            }
        }
    }
    print(dp[(1<<16)-1][500+K]);
}
0