QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398296#3763. Absolute Difference EquationGraphcity#AC ✓204ms5568kbC++20958b2024-04-25 10:27:582024-04-25 10:27:59

Judging History

This is the latest submission verdict.

  • [2024-04-25 10:27:59]
  • Judged
  • Verdict: AC
  • Time: 204ms
  • Memory: 5568kb
  • [2024-04-25 10:27:58]
  • Submitted

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e6,Mod=1e9+7;

inline int Pow(int x,int y)
{
    int res=1;
    while(y)
    {
        if(y&1) res=1ll*res*x%Mod;
        x=1ll*x*x%Mod,y>>=1;
    }
    return res;
}

int n; string s;

inline void Solve()
{
    n=s.size(),s=' '+s;
    int f[2]={1,0};
    For(i,1,n)
    {
        int k=((n-1)&(i-1))==(i-1);
        if(k==0)
        {
            f[0]=(1ll+(s[i]=='?'))*f[0]%Mod;
            f[1]=(1ll+(s[i]=='?'))*f[1]%Mod;
        }
        else
        {
            int g0=0,g1=0;
            if(s[i]!='1') (g0+=f[0])%=Mod,(g1+=f[1])%=Mod;
            if(s[i]!='0') (g1+=f[0])%=Mod,(g0+=f[1])%=Mod;
            f[0]=g0,f[1]=g1;
        }
    } cout<<f[1]<<endl;
}

int main()
{
    // freopen("1.in","r",stdin);

    while(cin>>s) Solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 204ms
memory: 5568kb

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