Submission #1032008

# Submission time Handle Problem Language Result Execution time Memory
1032008 2024-07-23T09:52:46 Z MarwenElarbi Match (CEOI16_match) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=5e4+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    optimise;
    string t;
    cin>>t;
    if(t.size()%2||t[0]!=t.back()){
        cout <<-1<<endl;
        return 0;
    }
    int cnt[26];
    memset(cnt,0,sizeof cnt);
    for (int i = 0; i < t.size(); ++i)
    {
       cnt[(int)(t[i]-'a')]++;
    } 
    bool test=true;
    for (int i = 0; i < 26; ++i)
    {
        if(cnt[i]%2) test=false;
    }
    if(!test){
        cout <<-1<<endl;
        return 0;
    }
    vector<int> tab[26];
    for (int i = 0; i < t.size(); ++i)
    {
        tab[t[i]-'a'].pb(i);
    }
    string ans=t;
    for (int i = 0; i < 26; ++i)
    {
        int lst=0;
        for (int j = 1; j < tab[i].size(); ++j)
        {
            if((tab[i][j]-tab[i][lst])%2==0&&(j-lst)%2) test=false;
            else if((tab[i][j])-tab[i][lst]%2==0){
                int a=0;
                for (int k = lst; k < j; ++k)
                {
                    a++;
                    if(a<=(j-lst)/2) ans[tab[i][lst]]='(';
                    else ans[tab[i][lst]]=')';
                }
            }
        }
        int a=0;
        for (int k = lst; k < tab[i].size(); ++k)
        {
            a++;
            if(a<=(tab[i].size()-lst)/2) ans[tab[i][k]]='(';
            else ans[tab[i][k]]=')';
        }
    }
    if(!test){
        cout <<-1<<endl;
        return 0;
    }
    cout <<ans<<endl;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < t.size(); ++i)
      |                     ~~^~~~~~~~~~
match.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < t.size(); ++i)
      |                     ~~^~~~~~~~~~
match.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j = 1; j < tab[i].size(); ++j)
      |                         ~~^~~~~~~~~~~~~~~
match.cpp:63:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int k = lst; k < tab[i].size(); ++k)
      |                           ~~^~~~~~~~~~~~~~~
match.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             if(a<=(tab[i].size()-lst)/2) ans[tab[i][k]]='(';
      |                ~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -