Submission #197626

# Submission time Handle Problem Language Result Execution time Memory
197626 2020-01-22T04:32:13 Z Rakhmand Match (CEOI16_match) C++14
10 / 100
2000 ms 25336 KB
//Feet don't fail me now
//Take me to the finish line
//Oh, my heart, it breaks every step that I take
//But I'm hoping at the gates, they'll tell me
//that IOI gold is mine
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define vectors vector<vector<llong> >
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long MXN = 2e5 + 10;
const long long MNN = 2e3 + 520;
const long long MOD = 2012;
const long long INF = 1e18;
const long long OO = 4e9;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

string s;
string ans = "";
int dp[MNN][MNN];

bool rec(int l, int r){
    if(l > r) return true;
    //if(dp[l][r] != -1) return dp[l][r];
    if(s[l] == s[r] && l < r){
        bool ok = rec(l + 1, r - 1);
        if(ok == true){
            ans[l] = '(';
            ans[r] = ')';
            return dp[l][r] = true;
        }
    }
    for(int i = r - 1; i > l; i--){
        if(rec(l, i) && rec(i + 1, r)){
            ans[l] = ans[i + 1] = '(';
            ans[i] = ans[r] = ')';
            dp[l][r] = dp[l][i] = dp[i + 1][r] = true;
            return true;
        }
    }
    return dp[l][r] = false;
}

int main() {
    ios;
    cin >> s;
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < s.size(); i++) ans += '-';
    bool ok = rec(0, s.size() - 1);
    if(ok == 0) cout << -1;
    else cout << ans;
}

Compilation message

match.cpp: In function 'bool rec(int, int)':
match.cpp:64:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
             return dp[l][r] = true;
                    ~~~~~~~~~^~~~~~
match.cpp:75:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     return dp[l][r] = false;
            ~~~~~~~~~^~~~~~~
match.cpp: In function 'int main()':
match.cpp:82:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size(); i++) ans += '-';
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25336 KB Output is correct
2 Correct 23 ms 25208 KB Output is correct
3 Correct 24 ms 25208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25336 KB Output is correct
2 Correct 23 ms 25208 KB Output is correct
3 Correct 24 ms 25208 KB Output is correct
4 Execution timed out 2077 ms 25208 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25336 KB Output is correct
2 Correct 23 ms 25208 KB Output is correct
3 Correct 24 ms 25208 KB Output is correct
4 Execution timed out 2077 ms 25208 KB Time limit exceeded
5 Halted 0 ms 0 KB -