Submission #59580

# Submission time Handle Problem Language Result Execution time Memory
59580 2018-07-22T12:27:51 Z octopuses Match (CEOI16_match) C++17
37 / 100
2000 ms 1324 KB
//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define ll long long
#define fr first
#define sc second
#define M 1000000007ll

using namespace std;

const int N = 100020;

int n;
char ch[N];
string a;
inline bool go(int v, stack < int > q)
{
  q.push(v);
  for(int i = v + 1; i <= n; ++ i)
  {
    if(!q.size() || a[q.top()] != a[i])
      q.push(i);
    else
      q.pop();
  }
  if(q.size())
    return false;
  return true;
}
stack < int > q;

int main()
{
  scanf("%s", &ch);
  a = "$" + string(ch) + "$";
  n = strlen(ch);
  for(int i = 1; i <= n; ++ i)
  {
    if(!q.size() || a[q.top()] != a[i])
      q.push(i);
    else
      q.pop();
  }
  if(q.size())
    return printf("-1"), 0;
  while(q.size()) q.pop();
  q.push(1); printf("(");
  for(int i = 2; i <= n; ++ i)
  {
    if(!q.size() || a[q.top()] != a[i])
      q.push(i), printf("(");
    else
    {
      if(go(i, q))
        q.push(i), printf("(");
      else
        q.pop(), printf(")");
    }
  }
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:35:18: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[100020]' [-Wformat=]
   scanf("%s", &ch);
               ~~~^
match.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", &ch);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 5 ms 572 KB Output is correct
6 Correct 6 ms 628 KB Output is correct
7 Correct 12 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 5 ms 572 KB Output is correct
6 Correct 6 ms 628 KB Output is correct
7 Correct 12 ms 628 KB Output is correct
8 Correct 101 ms 644 KB Output is correct
9 Correct 101 ms 644 KB Output is correct
10 Correct 84 ms 712 KB Output is correct
11 Correct 69 ms 760 KB Output is correct
12 Execution timed out 2054 ms 1324 KB Time limit exceeded
13 Halted 0 ms 0 KB -