제출 #398969

#제출 시각아이디문제언어결과실행 시간메모리
398969faresbasbs세 명의 친구들 (BOI14_friends)C++14
100 / 100
242 ms104032 KiB
#include <bits/stdc++.h> using namespace std; int n,dp[2000002][2]; string s,c,d; int ok(int curr , int tag){ if(curr-tag == d.size()){ return 1; } if(dp[curr][tag] != -1){ return dp[curr][tag]; } int ret = 0; if(!tag){ ret = ok(curr+1,1); } if(c[curr] == d[curr-tag]){ ret = max(ret,ok(curr+1,tag)); } return dp[curr][tag] = ret; } int main(){ cin >> n >> s; if(n%2 == 0){ cout << "NOT POSSIBLE" << endl; return 0; } string t1 = "" , t2 = "" , ans1 = "" , ans2 = ""; for(int i = 0 ; i < n/2 ; i += 1){ t1 += s[i]; } for(int i = n/2 ; i < n ; i += 1){ t2 += s[i]; } memset(dp,-1,sizeof dp); c = t2 , d = t1; if(ok(0,0)){ ans1 = t1; } t1 = "" , t2 = ""; for(int i = 0 ; i <= n/2 ; i += 1){ t1 += s[i]; } for(int i = n/2+1 ; i < n ; i += 1){ t2 += s[i]; } memset(dp,-1,sizeof dp); c = t1 , d = t2; if(ok(0,0)){ ans2 = t2; } if(ans1 == "" && ans2 == ""){ cout << "NOT POSSIBLE" << endl; }else if(ans1 == ""){ cout << ans2 << endl; }else if(ans2 == ""){ cout << ans1 << endl; }else if(ans1 == ans2){ cout << ans1 << endl; }else{ cout << "NOT UNIQUE" << endl; } }

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

friends.cpp: In function 'int ok(int, int)':
friends.cpp:7:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  if(curr-tag == d.size()){
      |     ~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...