이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <stack>
#define ff first
#define ss second
using namespace std;
string s;
int n, comma[7000005];
void pre() {
	stack<int> st;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == ')') {
			if(s[i + 1] == ',') {
				comma[st.top()] = i + 1;
				st.pop();
			}
		}
		if(s[i] == '(') {
			if(s[i + 2] == ',') comma[i] = i + 2;
			else st.push(i);
		}
	}
}
pair<int, int> solve(int l, int r) {
	if(l == r) return {0, 0};
	int cnt = 0, x = comma[l + 3];
	pair<int, int> a = solve(4 + l, x - 1), b = solve(x + 1, r - 1);
	if(s[1 + l] == 'i') return {a.ff + b.ff + 1, min(a.ss, b.ss)};
	else return {min(a.ff, b.ff), a.ss + b.ss + 1};
	return {0, 0};
}
int main() {
	memset(comma, -1, sizeof(comma));
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> s;
	pre();
	n = (int)s.size() / 7 + 1;
	pair<int, int> ans = solve(0, (int)s.size() - 1);
	cout << n - ans.ff - ans.ss;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void pre()':
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
Main.cpp: In function 'std::pair<int, int> solve(int, int)':
Main.cpp:45:6: warning: unused variable 'cnt' [-Wunused-variable]
   45 |  int cnt = 0, x = comma[l + 3];
      |      ^~~| # | 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... |