답안 #64385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64385 2018-08-04T09:15:19 Z Just_Solve_The_Problem popa (BOI18_popa) C++11
0 / 100
1000 ms 764 KB
#include "popa.h"
#include <bits/stdc++.h>

#define pb push_back
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair

using namespace std;

const int N = (int)1e3 + 7;

int pr[N];

//int query(int a, int b, int c, int d) {
//  printf("%d %d %d %d\n", a, b, c, d);
//  int gc1, gc2;
//  cin >> gc1 >> gc2;
//  return (gc1 == gc2);
//}

int solve(int n, int left[], int right[]) {
  for (int i = 0; i < n; i++) {
    left[i] = right[i] = -1;
    pr[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    int asd;
    if (i == 0) {
      asd = query(i, i, i, i + 1);
      if (asd) {
        pr[i + 1] = i;
        right[i] = i + 1;
      }
    } else if (i + 1 == n) {
      asd = query(i, i, i - 1, i);
      if (asd && right[pr[i]] != i && left[pr[i]] != i) {
        int temp = i - 1;
        while (pr[temp] != -1) {
          temp = pr[temp];
        }
        left[i] = temp;
        pr[temp] = i;
      }
    } else {
      asd = query(i, i, i - 1, i);
      if (asd && (pr[i] != -1 || right[pr[i]] != i && left[pr[i]] != i)) {
        int temp = i - 1;
        while (pr[temp] != -1) {
          temp = pr[temp];
        }
        left[i] = temp;
        pr[temp] = i;
      }
      asd = query(i, i, i, i + 1);
      if (asd) {
        pr[i + 1] = i;
        right[i] = i + 1;
      }
    }
  }
  int temp = 0;
  while (pr[temp] != -1) {
    temp = pr[temp];
  }
  return temp;
}

//main() {
//  int n;
//  cin >> n;
//  int a[n], b[n];
//  int root = solve(n, a, b);
//  cout << root << endl;
//  for (int i = 0; i < n; i++) {
//    cout << a[i] << ' ' << b[i] << endl;
//  }
//}

Compilation message

popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:48:52: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
       if (asd && (pr[i] != -1 || right[pr[i]] != i && left[pr[i]] != i)) {
                                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -