結果

問題 No.1284 Flip Game
ユーザー 👑 kmjpkmjp
提出日時 2020-11-06 22:53:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 4,131 ms
コンパイル使用メモリ 199,984 KB
実行使用メモリ 93,704 KB
最終ジャッジ日時 2023-09-29 19:23:04
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
93,508 KB
testcase_01 AC 26 ms
93,516 KB
testcase_02 AC 27 ms
93,508 KB
testcase_03 AC 26 ms
93,500 KB
testcase_04 AC 26 ms
93,444 KB
testcase_05 AC 28 ms
93,520 KB
testcase_06 AC 26 ms
93,432 KB
testcase_07 AC 26 ms
93,532 KB
testcase_08 AC 26 ms
93,452 KB
testcase_09 AC 27 ms
93,444 KB
testcase_10 AC 26 ms
93,436 KB
testcase_11 AC 25 ms
93,528 KB
testcase_12 AC 25 ms
93,704 KB
testcase_13 AC 26 ms
93,528 KB
testcase_14 AC 26 ms
93,436 KB
testcase_15 AC 26 ms
93,468 KB
testcase_16 AC 27 ms
93,472 KB
testcase_17 AC 29 ms
93,436 KB
testcase_18 AC 30 ms
93,584 KB
testcase_19 AC 44 ms
93,564 KB
testcase_20 AC 30 ms
93,644 KB
testcase_21 AC 30 ms
93,568 KB
testcase_22 AC 30 ms
93,576 KB
testcase_23 AC 43 ms
93,440 KB
testcase_24 AC 43 ms
93,568 KB
testcase_25 AC 43 ms
93,440 KB
testcase_26 AC 43 ms
93,500 KB
testcase_27 AC 43 ms
93,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int C[10][10];

ll dp[1024][1024][11];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(y,N) FOR(x,N) cin>>C[y][x];
	
	FOR(x,1024) FOR(y,1024) FOR(r,10) dp[x][y][r]=1LL<<60;
	FOR(r,N) dp[1<<r][0][r]=0;
	int m1,m2;
	ll ret=1LL<<60;
	FOR(m2,1<<N) FOR(m1,1<<N) FOR(x,N) if(dp[m1][m2][x]<1LL<<60) {
		FOR(y,N) if((m1&(1<<y))==0) { //初回
			int nm1,nm2;
			if(m2&(1<<x)) {
				nm1=m1|(1<<y);
				nm2=m2;
				dp[nm1][nm2][y]=min(dp[nm1][nm2][y],dp[m1][m2][x]+C[x][y]);
				if(nm1==(1<<N)-1) ret=min(ret,dp[nm1][nm2][y]);
			}
			else {
				nm1=(m1|(1<<y))^(1<<x);
				nm2=m2^(1<<x);
				dp[nm1][nm2][y]=min(dp[nm1][nm2][y],dp[m1][m2][x]+C[x][y]);
			}
		}
		
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0