제출 #670035

#제출 시각아이디문제언어결과실행 시간메모리
670035LucaDantasHomework (CEOI22_homework)C++17
53 / 100
1086 ms7348 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second constexpr int maxn = 1e6+10; char s[7*maxn + 10]; int idx[7*maxn + 10]; vector<pair<pair<int,int>,int>> itv; struct NodeAns { int l, r, sz; }; NodeAns solve(int x) { if(itv[x].ff.ff == itv[x].ff.ss) return {1, 1, 1}; auto itvL = solve(x+1), itvR = solve(idx[itv[x+1].ss]); if(s[itv[x].ff.ff-1] == 'x') // max return {itvL.l + itvR.l, max(itvL.r + itvR.sz, itvL.sz + itvR.r), itvL.sz + itvR.sz}; else // min return {min(itvL.l, itvR.l), itvL.r + itvR.r - 1, itvL.sz + itvR.sz}; } int main() { scanf(" %s", s); vector<int> open; for(int i = 0; i < (int)strlen(s); i++) if(s[i] == '(') { if(itv.size() && !itv.back().ss) itv.back().ss = i; open.push_back(i); } else if(s[i] == ')') itv.push_back({{open.back(), i}, 0}), open.pop_back(); else if(s[i] == '?') { if(itv.size() && !itv.back().ss) itv.back().ss = i; itv.push_back({{i, i}, 0}); // intervals with same beginning and end are question marks } sort(itv.begin(), itv.end()); // sorts by the opening bracket for(int i = 0; i < (int)itv.size(); i++) idx[itv[i].ff.ff] = i; auto [l, r, sz] = solve(0); printf("%d\n", r-l+1); }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf(" %s", s);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...