QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187795 | #1085. Brave Seekers of Unicorns | SublimeText | WA | 1ms | 3612kb | C++14 | 1.2kb | 2023-09-24 22:43:55 | 2023-09-24 22:43:56 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_set>
#include <assert.h>
#include <bitset>
using namespace std;
#define REP(i, l, r) for(int i = l; i <= r; ++i)
#define PER(i, r, l) for(int i = r; i >= l; --i)
namespace Main {
const int N = 1e6 + 5;
int n, mod;
int f[N];
void add(int &x, int y) {
x += y;
if (x < 0) x += mod;
if(x >= mod) x -= mod;
}
int lg[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> mod;
lg[0] = -1;
for(int i = 1; i <= n; ++i) {
f[i] = 1;
add(f[i], f[i - 1]);
lg[i] = lg[i >> 1] + 1;
for (int j = 0; (i >> j) > 1; ++j) {
if((i >> j) & 1) {
add(f[i], -f[(1 << (j + 1)) - 1]);
add(f[i], f[(1 << j) - 1]);
}
}
add(f[i], f[i - 1]);
}
cout << f[n] << '\n';
return 0;
}
}
int main() {
// freopen("sort.in", "r", stdin);
// freopen("sort.out", "w", stdout);
Main :: main();
return 0;
}
/*
5
4 5 1 2 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
2
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
3
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
5
output:
26
result:
ok 1 number(s): "26"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
322
output:
-1431480283
result:
wrong answer 1st numbers differ - expected: '782852421', found: '-1431480283'