Submission #41399343
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define pii pair<ll, ll>
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
#define int long long
int dp[64][2];
int f(string &s, int n, int pos, int found) {
if(pos < 0) {
return 0LL;
}
if(dp[pos][found] != -1)
return dp[pos][found];
bool found_now = found;
int bit = (n >> pos) & 1;
if(pos >= s.length()) {
if(bit)
found_now = 1;
return dp[pos][found] = f(s, n, pos - 1, found_now);
}
if(s[s.length() - 1 - pos] == '?') {
if(found) {
return dp[pos][found] = (1LL << pos) + f(s, n, pos - 1, found);
} else {
return dp[pos][found] = max((bit << pos) + f(s, n, pos - 1, found), f(s, n, pos - 1, found | bit));
}
}
int other = s[s.length() - 1 - pos] - '0';
if(!found && other > bit) {
return dp[pos][found] = -INF;
}
if(other < bit)
found_now = 1;
return dp[pos][found] = (other << pos) + f(s, n, pos - 1, found_now);
}
void run_case(){
string s;
int n;
cin >> s;
cin >> n;
int len = s.length();
mem1(dp);
cout << max(-1LL, f(s, n, 62, 0)) << nl;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
run_case();
}
Submission Info
Submission Time
2023-05-14 01:20:45+0900
Task
D - Bitmask
User
saturnbored
Language
C++ (GCC 9.2.1)
Score
400
Code Size
2203 Byte
Status
AC
Exec Time
7 ms
Memory
3600 KiB
Compile Error
./Main.cpp: In function ‘long long int f(std::string&, long long int, long long int, long long int)’:
./Main.cpp:41:12: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
41 | if(pos >= s.length()) {
| ~~~~^~~~~~~~~~~~~
./Main.cpp: In function ‘void run_case()’:
./Main.cpp:73:9: warning: unused variable ‘len’ [-Wunused-variable]
73 | int len = s.length();
| ^~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
400 / 400
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random1_00.txt, 01_random1_01.txt, 01_random1_02.txt, 01_random1_03.txt, 01_random1_04.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 04_random4_00.txt, 04_random4_01.txt, 04_random4_02.txt, 04_random4_03.txt, 04_random4_04.txt, 04_random4_05.txt, 04_random4_06.txt, 04_random4_07.txt, 05_random5_00.txt, 05_random5_01.txt, 05_random5_02.txt, 05_random5_03.txt, 05_random5_04.txt, 05_random5_05.txt, 05_random5_06.txt, 05_random5_07.txt, 06_handmade_00.txt, 06_handmade_01.txt, 06_handmade_02.txt, 06_handmade_03.txt, 06_handmade_04.txt, 06_handmade_05.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
7 ms
3544 KiB
00_sample_01.txt
AC
2 ms
3576 KiB
00_sample_02.txt
AC
2 ms
3516 KiB
01_random1_00.txt
AC
2 ms
3592 KiB
01_random1_01.txt
AC
2 ms
3460 KiB
01_random1_02.txt
AC
2 ms
3600 KiB
01_random1_03.txt
AC
2 ms
3456 KiB
01_random1_04.txt
AC
2 ms
3580 KiB
02_random2_00.txt
AC
2 ms
3400 KiB
02_random2_01.txt
AC
2 ms
3516 KiB
02_random2_02.txt
AC
2 ms
3528 KiB
02_random2_03.txt
AC
2 ms
3444 KiB
02_random2_04.txt
AC
3 ms
3592 KiB
02_random2_05.txt
AC
2 ms
3532 KiB
02_random2_06.txt
AC
2 ms
3600 KiB
02_random2_07.txt
AC
2 ms
3444 KiB
03_random3_00.txt
AC
2 ms
3456 KiB
03_random3_01.txt
AC
2 ms
3540 KiB
03_random3_02.txt
AC
2 ms
3512 KiB
03_random3_03.txt
AC
5 ms
3460 KiB
03_random3_04.txt
AC
2 ms
3596 KiB
03_random3_05.txt
AC
2 ms
3532 KiB
03_random3_06.txt
AC
2 ms
3592 KiB
03_random3_07.txt
AC
2 ms
3524 KiB
04_random4_00.txt
AC
2 ms
3460 KiB
04_random4_01.txt
AC
1 ms
3536 KiB
04_random4_02.txt
AC
2 ms
3536 KiB
04_random4_03.txt
AC
2 ms
3528 KiB
04_random4_04.txt
AC
2 ms
3400 KiB
04_random4_05.txt
AC
2 ms
3460 KiB
04_random4_06.txt
AC
2 ms
3592 KiB
04_random4_07.txt
AC
2 ms
3528 KiB
05_random5_00.txt
AC
2 ms
3456 KiB
05_random5_01.txt
AC
2 ms
3456 KiB
05_random5_02.txt
AC
2 ms
3536 KiB
05_random5_03.txt
AC
2 ms
3544 KiB
05_random5_04.txt
AC
2 ms
3592 KiB
05_random5_05.txt
AC
2 ms
3460 KiB
05_random5_06.txt
AC
2 ms
3512 KiB
05_random5_07.txt
AC
2 ms
3600 KiB
06_handmade_00.txt
AC
2 ms
3580 KiB
06_handmade_01.txt
AC
2 ms
3592 KiB
06_handmade_02.txt
AC
2 ms
3460 KiB
06_handmade_03.txt
AC
2 ms
3476 KiB
06_handmade_04.txt
AC
2 ms
3404 KiB
06_handmade_05.txt
AC
2 ms
3576 KiB