제출 #115244

#제출 시각아이디문제언어결과실행 시간메모리
115244sebinkim괄호 문자열 (CEOI16_match)C++14
100 / 100
32 ms1400 KiB
#include <bits/stdc++.h> using namespace std; char s[101010]; int dp[101010]; int n; void die() { printf("-1\n"); exit(0); } int make(int p, int r) { int i, ret; ret = -1; for(i=p+1; i<r; i=dp[i]+1){ if(s[i] == s[p]) ret = i; } if(ret == -1) die(); s[p] = '('; s[ret] = ')'; for(i=p+1; i<ret; ){ if(dp[i] == n) die(); i = make(i, ret) + 1; if(i > ret) die(); } return ret; } int main() { int i, j; scanf("%s", s); n = strlen(s); for(i=n-1; i>=0; i--){ for(j=i+1; s[i] != s[j] && j<n; j=dp[j]+1); dp[i] = j; } for(i=0; i<n; ){ if(dp[i] == n) die(); i = make(i, n) + 1; if(i > n) die(); } printf("%s\n", s); return 0; }

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

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