結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2023-01-25 23:17:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 635 bytes |
コンパイル時間 | 1,935 ms |
コンパイル使用メモリ | 204,716 KB |
最終ジャッジ日時 | 2025-02-10 06:51:21 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 26 TLE * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {int n;cin>>n;vector<vector<int>> dp(n+1, vector<int>(n+1));map<int,int> bits;for(int i=1; i<=n; i++){bitset<32> bs(i);bits[i] = bs.count();}dp[0][1]=1;for(int i=0; i<n; i++){if(dp[i][n]){cout << i+1 << endl;return 0;}for(int j=1; j<=n; j++){if(bits[j]<j){dp[i+1][j-bits[j]] = 1;}if(j+bits[j]<=n){dp[i+1][j+bits[j]] =1;}}}cout << -1 << endl;return 0;}