結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
tubo28
|
| 提出日時 | 2015-09-09 17:53:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,069 bytes |
| コンパイル時間 | 2,407 ms |
| コンパイル使用メモリ | 201,204 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2024-07-19 05:04:37 |
| 合計ジャッジ時間 | 6,131 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 5 RE * 22 |
コンパイルメッセージ
main.cpp: In instantiation of ‘size_t popcount(T) [with T = int; size_t = long unsigned int]’:
main.cpp:103:25: required from ‘int solve(T) [with T = int]’
main.cpp:119:33: required from here
main.cpp:86:44: warning: right shift count >= width of type [-Wshift-count-overflow]
86 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M];
| ~^~~~
main.cpp:86:58: warning: right shift count >= width of type [-Wshift-count-overflow]
86 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M];
| ~^~~~
main.cpp:88:44: warning: right shift count >= width of type [-Wshift-count-overflow]
88 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>>80&M] + dp[x>>96&M] + dp[x>>112&M];
| ~^~~~
main.cpp:88:58: warning: right shift count >= width of type [-Wshift-count-overflow]
88 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>>80&M] + dp[x>>96&M] + dp[x>>112&M];
| ~^~~~
main.cpp:88:72: warning: right shift count >= width of type [-Wshift-count-overflow]
88 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>>80&M] + dp[x>>96&M] + dp[x>>112&M];
| ~^~~~
main.cpp:88:86: warning: right shift count >= width of type [-Wshift-count-overflow]
88 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>>80&M] + dp[x>>96&M] + dp[x>>112&M];
| ~^~~~
main.cpp:88:100: warning: right shift count >= width of type [-Wshift-count-overflow]
88 | return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>
ソースコード
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
_ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
<< " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
sort(l,l+n);
return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;
template<typename T> inline size_t popcount(T x){
static_assert(is_integral<T>::value,
"popcount : must be integer.");
static_assert(sizeof(x) == sizeof(int8_t) ||
sizeof(x) == sizeof(int16_t) ||
sizeof(x) == sizeof(int32_t) ||
sizeof(x) == sizeof(int64_t) ||
sizeof(x) == sizeof(__int128_t),
"popcount : must be 8, 16, 32, 64, or 128 bits.");
static const int M = 65535;
static size_t dp[66000];
if(dp[M] != 16) for(int i = 0; i <= M; i++) dp[i] = (i&1) + dp[i>>1];
switch(sizeof(T)){
case sizeof(int8_t):
return dp[x];
case sizeof(int16_t):
return dp[(int8_t)x];
case sizeof(int32_t):
return dp[x&M] + dp[x>>16&M];
case sizeof(int64_t):
return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M];
case sizeof(__int128_t):
return dp[x&M] + dp[x>>16&M] + dp[x>>32&M] + dp[x>>48&M] + dp[x>>64&M] + dp[x>>80&M] + dp[x>>96&M] + dp[x>>112&M];
}
}
template<class T>
int solve(T n){
queue<T> q;
q.push(1);
int dist[11111];
fill_n(dist,11111,1e9);
dist[1] = 0;
while(q.size()){
T c = q.front();
q.pop();
if(c == n) return dist[c];
int d = popcount(c);
for(int w : {1,-1}){
T nx = c + d*w;
if(1 <= nx && nx <= n && dist[nx] > dist[c] + 1){
dist[nx] = dist[c] + 1;
q.push(nx);
}
}
}
return -1;
}
int main(){
int N;
while(cin >> N){
vector<int> ans;
ans.pb(solve<signed int>(N));
ans.pb(solve<signed char>(N));
ans.pb(solve<signed short>(N));
ans.pb(solve<signed long>(N));
ans.pb(solve<signed long long>(N));
ans.pb(solve<unsigned int>(N));
ans.pb(solve<unsigned char>(N));
ans.pb(solve<unsigned short>(N));
ans.pb(solve<unsigned long>(N));
ans.pb(solve<unsigned long long>(N));
dump(ans);
assert(all_of(ans.begin(),ans.end(),[&](int a){
return a == ans[0];
}));
cout << ans[0] << endl;
}
}
tubo28