QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189896 | #1085. Brave Seekers of Unicorns | KKT89 | AC ✓ | 74ms | 11592kb | C++17 | 1.6kb | 2023-09-28 01:22:05 | 2023-09-28 01:22:06 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
const int N = 1e6+1;
constexpr int mod = 998244353;
int dp[N];
int sdp[N];
void add(int &x, int y){
x += y;
if(x >= mod)x -= mod;
}
void sub(int &x,int y){
x -= y;
if(x < 0)x += mod;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
dp[0] = sdp[0] = 1;
for(int i=1;i<=n;i++){
dp[i] = sdp[i-1];
sdp[i] = sdp[i-1];
int j = 0;
for(int k=0;k<30;k++){
if((1<<k)&i)j = k;
}
for(int k=0;k<j;k++){
if((1<<k)&i){
int v = sdp[(1<<(k+1)) - 1];
sub(v, sdp[(1<<k)-1]);
sub(dp[i], v);
}
}
add(sdp[i], dp[i]);
}
cout << (sdp[n]-1+mod)%mod << endl;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5704kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
2
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
3
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5644kb
input:
5
output:
26
result:
ok 1 number(s): "26"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
322
output:
782852421
result:
ok 1 number(s): "782852421"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
10
output:
728
result:
ok 1 number(s): "728"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
100
output:
234222727
result:
ok 1 number(s): "234222727"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5800kb
input:
10000
output:
348787098
result:
ok 1 number(s): "348787098"
Test #9:
score: 0
Accepted
time: 74ms
memory: 11408kb
input:
1000000
output:
246427510
result:
ok 1 number(s): "246427510"
Test #10:
score: 0
Accepted
time: 70ms
memory: 11592kb
input:
999999
output:
525546416
result:
ok 1 number(s): "525546416"
Test #11:
score: 0
Accepted
time: 70ms
memory: 11204kb
input:
950000
output:
154241852
result:
ok 1 number(s): "154241852"
Test #12:
score: 0
Accepted
time: 74ms
memory: 11460kb
input:
999888
output:
254589934
result:
ok 1 number(s): "254589934"
Test #13:
score: 0
Accepted
time: 74ms
memory: 11468kb
input:
999423
output:
917909701
result:
ok 1 number(s): "917909701"
Test #14:
score: 0
Accepted
time: 40ms
memory: 11536kb
input:
600000
output:
546076071
result:
ok 1 number(s): "546076071"
Test #15:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
1337
output:
616951443
result:
ok 1 number(s): "616951443"