답안 #971581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971581 2024-04-29T03:16:16 Z vjudge1 Homework (CEOI22_homework) C++17
0 / 100
20 ms 15536 KB
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 1e5 + 10;

pair<int, int> st[N];

int t[N];

int operation[N];

int child[2][N], a[N], order[N];

bool dd[N];

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  string str; cin >> str;


  int p;

  int id = 0, _id = 0;

  for(char c : str) if (c == '?') _id++;
  int n = _id;

  for(int i = 0; i < str.size(); i++) {
    if (str[i] == 'm') {
      i += 3;
      st[++p] = make_pair(0, 0);
      if (i - 1 >= str.size()) exit(0);
      t[p] = str[i - 1] == 'x';
//      cout << str[i - 1] << " " << t[p] << endl;
    }
    else if (str[i] == '?') {
      ++id;
      if (st[p].first == 0) st[p].first = id;
      else st[p].second = id;
    }
    else if (str[i] == ')') {
      ++_id;
      if (st[p].first == 0 || st[p].second == 0) exit(0);
      assert(st[p].first && st[p].second);
      child[0][_id] = st[p].first;
      child[1][_id] = st[p].second;
      operation[_id] = t[p];
//      cout << _id << " " << st[p].first << " " << st[p].second << " " << operation[_id] << endl;
      --p;
      if (p < 0) exit(0);
      assert(p >= 0);
      if (st[p].first == 0) st[p].first = _id;
      else st[p].second = _id;
    }
  }
  exit(0);

  auto dfs = [&] (auto self, int u) {
    if (u <= n) {
      a[u] = order[u];
      return;
    }
    self(self, child[0][u]);
    self(self, child[1][u]);
    if (operation[u]) a[u] = max(a[child[0][u]], a[child[1][u]]);
    else a[u] = min(a[child[0][u]], a[child[1][u]]);
  };

  for(int i = 1; i <= n; i++) order[i] = i;
  do {
//    for(int i = 1; i <= n; i++) cerr << order[i] << " "; cerr << endl;
    dfs(dfs, _id);
    dd[a[_id]] = 1;
  } while (next_permutation(order + 1, order + n + 1));


  int ans = 0;
  for(int i = 1; i <= n; i++) ans += dd[i];
  cout << ans;
}



Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int i = 0; i < str.size(); i++) {
      |                  ~~^~~~~~~~~~~~
Main.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |       if (i - 1 >= str.size()) exit(0);
      |           ~~~~~~^~~~~~~~~~~~~
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:15: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |       st[++p] = make_pair(0, 0);
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 15536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -