QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398521#3763. Absolute Difference EquationHjcc2AC ✓78ms4576kbC++14853b2024-04-25 14:26:512024-04-25 14:26:52

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 14:26:52]
  • 评测
  • 测评结果:AC
  • 用时:78ms
  • 内存:4576kb
  • [2024-04-25 14:26:51]
  • 提交

answer

# include <bits/stdc++.h>
# define ll long long

using namespace std;

const int N = 1e6 + 5;
char s[N];
ll ans = 1, cnt = 0;
const ll mod = 1e9 + 7;

bool ck(int i, int n) {
  return (i | n - 1) == (n - 1);
}

int main() {
# ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
# endif
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  while (cin >> s) {
    int n = strlen(s);
    bool fl = 0, now = 0; cnt = 0; ans = 1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '?') {
        ++cnt, fl |= (ck(i, n));
      } else {
        now ^= (ck(i, n) && (s[i] == '1'));
      }
    }
    if (fl == 0 && now == 0) {
      cout << 0 << '\n';
    } else {
      cnt -= fl;
      while (cnt--) {
        ans = ans * 2 % mod;
      }
      cout << ans << '\n';
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 78ms
memory: 4576kb

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