Submission #874873

# Submission time Handle Problem Language Result Execution time Memory
874873 2023-11-18T02:46:58 Z Muhammad_Aneeq Match (CEOI16_match) C++17
0 / 100
0 ms 348 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
inline void solve()
{
	string x;
	cin>>x;
	int n=x.size();
	map<char,vector<int>>d;
	for (int i=0;i<n;i++)
		d[x[i]].push_back(i);
	for (auto i:d)
	{
		if (i.second.size()%2)
		{
			cout<<-1<<endl;return;
		}
	}
	string ans=string(n,' ');
	for (auto i:d)
	{
		vector<int>x,y;
		for (auto j:i.second)
			if (j%2)
				x.push_back(j);
			else
				y.push_back(j);
		if (x.size()!=y.size())
		{
			cout<<-1<<endl;return;
		}
		if (x[0]>y[0])
			swap(x,y);
		reverse(y.begin(), y.end());
		for (int i=0;i<x.size();i++)
		{
			int z=min(x[i],y[i]);
			ans[z]='(';
			ans[y[i]+x[i]-z]=')';
		}
	}
	cout<<ans<<endl;
}
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}

Compilation message

match.cpp: In function 'void solve()':
match.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i=0;i<x.size();i++)
      |                ~^~~~~~~~~
# 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 -