QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309420 | #8025. Fibonacci | PetroTarnavskyi# | WA | 0ms | 3668kb | C++20 | 1.9kb | 2024-01-20 17:14:16 | 2024-01-20 17:14:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1e9 + 7;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
const int N = 30;
int dp[N][2][2];
int x, y;
int f(int len, int ex, int ey)
{
if (len == N)
return 1;
if (dp[len][ex][ey] != -1)
return dp[len][ex][ey];
dp[len][ex][ey] = 0;
int btx = ((x >> (N - len - 1)) & 1);
int bty = ((y >> (N - len - 1)) & 1);
FOR (bx, 0, 2)
{
if (ex && bx > btx)
continue;
int nex = ex && bx == btx;
FOR (by, 0, 2)
{
if (ey && by > bty)
continue;
if (ey == ex && ey == 1)
continue;
int ney = ey && by == bty;
add(dp[len][ex][ey], f(len + 1, nex, ney));
}
}
return dp[len][ex][ey];
}
void solve()
{
FOR (i, 0, N) FOR (j, 0, 2) FOR (k, 0, 2) dp[i][j][k] = -1;
cin >> x >> y;
int eqx = 1;
int eqy = 1;
int ans = 0;
FOR (i, 0, N)
{
int btx = (x >> (N - 1 - i)) & 1;
int bty = (y >> (N - 1 - i)) & 1;
FOR (bx, 0, 2)
{
if (eqx && bx > btx)
continue;
FOR (by, 0, 2)
{
if (eqy && by > bty)
continue;
if (bx == by)
continue;
ans = add(ans, mult(N - i, f(i + 1, eqx && bx == btx, eqy && by == bty)));
}
}
eqx &= btx == 0;
eqy &= bty == 0;
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
1
output:
0
result:
ok answer is '0'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
2
output:
0 0
result:
wrong output format Extra information in the output file