이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define Nahida ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define int long long
const int N = 1e6 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e17 ;
int n ;
string s ;
int mx( int l , int r ){
if ( l == r ) return 1 ;
int ll = l+3 , cnt = 0 ;
while ( ll ++ ){
if ( s[ll] == '(' ) cnt ++ ;
if ( s[ll] == ')' ) cnt -- ;
if ( s[ll] == ',' && cnt == 0 ) break ;
}
int cl = mx ( l+4 , ll-1 ) ;
int cr = mx ( ll+1 , r-1 ) ;
if ( s[l+1] == 'i' ) return cl + cr ;
else return min( cl , cr ) ;
}
int mn( int l , int r ){
if ( l == r ) return 1 ;
int ll = l+3 , cnt = 0 ;
while ( ll ++ ){
if ( s[ll] == '(' ) cnt ++ ;
if ( s[ll] == ')' ) cnt -- ;
if ( s[ll] == ',' && cnt == 0 ) break ;
}
int cl = mn ( l+4 , ll-1 ) ;
int cr = mn ( ll+1 , r-1 ) ;
if ( s[l+1] == 'a' ) return cl + cr ;
else return min( cl , cr ) ;
}
signed main(){
// Nahida ;
cin >> s ;
for ( int i = 0 ; i < s.size() ; i ++ ) if ( s[i] == '?' ) n ++ ;
int l = mn( 0 , s.size() - 1 ) ;
int r = n-mx( 0 , s.size() - 1 )+1 ;
// cout << l << ' ' << r << endl ;
cout << r - l + 1 ;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:50:22: 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]
50 | for ( int i = 0 ; i < s.size() ; i ++ ) if ( s[i] == '?' ) n ++ ;
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |