結果

問題 No.3 ビットすごろく
ユーザー hogeover30hogeover30
提出日時 2015-02-01 04:15:53
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 648 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 51,236 KB
最終ジャッジ日時 2024-04-27 02:06:23
合計ジャッジ時間 818 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:9: error: ‘vector’ was not declared in this scope
    9 |         vector<unsigned> v(n+10, -1);
      |         ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:9:16: error: expected primary-expression before ‘unsigned’
    9 |         vector<unsigned> v(n+10, -1);
      |                ^~~~~~~~
main.cpp:10:9: error: ‘v’ was not declared in this scope
   10 |         v[1]=1;
      |         ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    while (cin>>n) {
        vector<unsigned> v(n+10, -1);
        v[1]=1;
        bool changed=true;
        while (changed) {
            changed=false;
            for(int i=1;i<=n;++i) if (v[i]!=-1) {
                int k=__builtin_popcount(i);
                if (v[i+k]>v[i]+1) {
                    v[i+k]=v[i]+1;
                    changed=true;
                }
                if (v[i-k]>v[i]+1) {
                    v[i-k]=v[i]+1;
                    changed=true;
                }
            }
        }
        cout<<(int)v[n]<<endl;
    }
}
0