QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#959251 | #3763. Absolute Difference Equation | xianjing# | AC ✓ | 184ms | 20400kb | C++23 | 4.5kb | 2025-03-31 17:05:00 | 2025-03-31 17:05:00 |
Judging History
answer
//.................................................................................
//..................##..............##..................###....#####....####.......
//..................##..............##.................#####..##...##..#####.......
//..................##..............##................###.###.##...##..##..........
//......##..###..##.##.##...#####...##....####........##...##.##...##.##.###.......
//......##..###..##.######..######..##...######.......##...##..#####..#######......
//.......#..###..##.##..##......##..##..##...##.......##...##..#####..##...##......
//.......####.####..##..##..######..##..#######.####..##...##.##...##.##...##......
//.......####.####..##..##.##...##..##..##............###.###.##...##.##...##......
//........##..####..##..##.#######..##..######.........#####..##...##..#####.......
//........##...##...##..##..###.##..##...#####..........###....#####....###........
//.................................................................................
/**
* 2025-03-31 16:33:40
**/
//#pragma GCC optimize(1, 2, 3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define all1(x) x.begin() + 1, x.end()
#define sort_all(x) sort(all(x))
#define sort1_all(x) sort(all1(x))
#define reverse_all(x) reverse(all(x))
#define reverse1_all(x) reverse(all1(x))
using i128 = __int128;
using ll=long long;
#define ldb long double
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ldb, ldb> pdd;
typedef pair<ll, int> pli;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<string, int> msi;
#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"
// 红色
#define DEBUG1(x) \
RED; \
cout << #x << " : " << x << endl; \
RESET;
// 绿色
#define DEBUG2(x) \
GREEN; \
cout << #x << " : " << x << endl; \
RESET;
// 蓝色
#define DEBUG3(x) \
BLUE; \
cout << #x << " : " << x << endl; \
RESET;
// 品红
#define DEBUG4(x) \
MAGENTA; \
cout << #x << " : " << x << endl; \
RESET;
// 青色
#define DEBUG5(x) \
CYAN; \
cout << #x << " : " << x << endl; \
RESET;
// 黄色
#define DEBUG6(x) \
YELLOW; \
cout << #x << " : " << x << endl; \
RESET;
#define dddmin(x,y) (x=min(x,y))
#define dddmax(x,y) (x=max(x,y))
const int mod=1e9+7;
//const int mod=998244353;
random_device RD;
mt19937_64 rd(RD());
ll rn(int l, int r){
return l + rd() % (r - l + 1);
}
int qpow(int a,int b){
int base=1;
while(b){
if(b&1)base=base*a%mod;
b>>=1;
a=a*a%mod;
}
return base;
}
inline int lowbit(int x){
return x&-x;
}
inline int lt(int x){
return 1ll<<x;
}
const int maxn = 1e6 + 5;
int fact[maxn], invfact[maxn];
void solve(){
//不可水群!!!!
//戒焦躁!!!!
//专注!!!
fact[0] = 1;
for(int i = 1; i < maxn; i ++)
fact[i] = fact[i - 1] * i % mod;
invfact[maxn - 1] = qpow(fact[maxn - 1], mod - 2);
for(int i = maxn - 1; i; i --)
invfact[i - 1] = invfact[i] * i % mod;
auto C = [&](int x, int y)->int{
if(y > x)
return 0;
return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
};
string s;
while(cin >> s){
int n = s.size();
int cnt = 0, now = 0, ans = 1;
for(int i = 0; i < n; i ++){
bool ok = 1;//是否有影响
for(int j = 0; j < 22; j ++){
if((i >> j & 1) && !((n - 1) >> j & 1)){
ok = 0;
break;
}
}
if(ok){
if(s[i] == '1')
now ^= 1;
else if(s[i] == '?')
cnt ++;
}
else{
if(s[i] == '?')
ans = (ans << 1) % mod;
}
}
int ans1 = 0;
for(int i = now ^ 1; i <= cnt; i += 2){
ans1 += C(cnt, i);
ans1 %= mod;
}
cout << ans * ans1 % mod << "\n";
}
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int ____=1;
// cin>>____;
while(____--)solve();
return 0;
}
//火车头长度 141
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 184ms
memory: 20400kb
input:
1 ????? 1010?1?0 0 1 ? 00 10 ?0 01 11 ?1 0? 1? ?? 000 100 ?00 010 110 ?10 0?0 1?0 ??0 001 101 ?01 011 111 ?11 0?1 1?1 ??1 00? 10? ?0? 01? 11? ?1? 0?? 1?? ??? 0000 1000 ?000 0100 1100 ?100 0?00 1?00 ??00 0010 1010 ?010 0110 1110 ?110 0?10 1?10 ??10 00?0 10?0 ?0?0 01?0 11?0 ?1?0 0??0 1??0 ???0 0001 10...
output:
1 16 2 0 1 1 0 1 1 1 0 1 1 1 2 0 1 1 0 1 1 0 2 2 1 0 1 1 0 1 2 0 2 1 1 2 1 1 2 2 2 4 0 1 1 1 0 1 1 1 2 1 0 1 0 1 1 1 1 2 1 1 2 1 1 2 2 2 4 1 0 1 0 1 1 1 1 2 0 1 1 1 0 1 1 1 2 1 1 2 1 1 2 2 2 4 1 1 2 1 1 2 2 2 4 1 1 2 1 1 2 2 2 4 2 2 4 2 2 4 4 4 8 0 1 1 0 1 1 0 2 2 0 1 1 0 1 1 0 2 2 0 2 2 0 2 2 0 4 4...
result:
ok 162656 lines