結果
| 問題 |
No.1360 [Zelkova 4th Tune] 協和音
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2021-01-22 21:33:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 97 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 1,674 ms |
| コンパイル使用メモリ | 172,548 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-27 21:56:57 |
| 合計ジャッジ時間 | 6,807 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:52:12: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
52 | ans>>=1;
| ~~~^~~~
main.cpp:27:9: note: 'ans' was declared here
27 | int ans; ll mx=-INF;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;
ll power(ll x, ll y, ll m){
x%=m;
ll ret=1;
while(y){
if(y&1) ret=ret*x%m;
x=x*x%m;
y>>=1;
}
return ret;
}
int main(){
int n; cin >> n;
VI a(n); REP(i,n) cin >> a[i];
VVI b(n,VI(n)); REP(i,n)REP(j,n) cin >> b[i][j];
int ans; ll mx=-INF;
for(int i=1;i<(1<<n);i++){
int p=i, q;
ll sum=0;
REP(j,n){
if(p&1){
sum+=a[j];
q=i;
REP(k,j){
if(q&1)
sum+=b[j][k];
q>>=1;
}
}
p>>=1;
}
if(mx<sum){
mx=sum;
ans=i;
}
}
cout << mx << endl;
REP(i,n){
if(ans&1)
cout << i+1 << " ";
ans>>=1;
}
cout << endl;
return 0;
}
Haa