제출 #1252659

#제출 시각아이디문제언어결과실행 시간메모리
1252659Clan3283개의 봉우리 (IOI25_triples)C++20
컴파일 에러
0 ms0 KiB
#include "triples.h"
#include <bits/stdc++.h>

using namespace std;

long long count_triples(std::vector<int> h) {
  int n = h.size();

  long long res = 0;

  bool nonDec = true;
  for (int i = 0; i < n-1; i++) nonDec &= h[i] <= h[i+1];

  if (n <= 2000) {
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
        if (h[i]+j < n) {
          vector<int> a = {h[i], h[j], h[h[i]+j]};
          vector<int> b = {j-i, h[i], h[i]+j-i};
          sort(a.begin(), a.end());
          sort(b.begin(), b.end());

          if (a == b) res++;
        }

        if (h[j]+j < n && h[i] != h[j]) {
          vector<int> a = {h[i], h[j], h[h[j]+j]};
          vector<int> b = {j-i, h[j], h[j]+j-i};
          sort(a.begin(), a.end());
          sort(b.begin(), b.end());
          
          if (a == b) res++;
        }

        if (abs(h[i]-h[j])+j < n && h[i] != abs(h[i]-h[j]) && h[j] != abs(h[i]-h[j])) {
          vector<int> a = {h[i], h[j], h[abs(h[i]-h[j])+j]};
          vector<int> b = {j-i, abs(h[i]-h[j]), abs(h[i]-h[j])+j-i};
          sort(a.begin(), a.end());
          sort(b.begin(), b.end());
          
          if (a == b) res++;
        }
      }
    }
  } else if (nonDec) {
    for (int i = 0; i < n; i++) {
      bool already = false;
      if (h[i]+i < n && h[i]+i-h[h[i]+i] >= 0) {
        vector<int> a = {h[i], h[h[i]+i], h[h[i]+i-h[h[i]+i]]};
        vector<int> b = {h[i], i-h[h[i]+i], h[h[i]+i]};
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());

        if (a == b) {
          already = true;
          res++;
        }
      }

      if (h[i]-i >= 0 && i+h[h[i]-i] < n) {
        vector<int> a = {h[i], h[i+h[h[i]-i]], h[h[i]-i]};
        vector<int> b = {h[i], h[h[i]-i], 2*i-h[i]-h[h[i]-i]};
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());

        if (a == b && (!already || h[i]+i-h[h[i]+i] != h[i]-i)) res++;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n && j < i+20; j++) {
        if (h[i]+j < n) {
          vector<int> a = {h[i], h[j], h[h[i]+j]};
          vector<int> b = {j-i, h[i], h[i]+j-i};
          sort(a.begin(), a.end());
          sort(b.begin(), b.end());

          if (a == b) res++;
        }

        if (h[j]+j < n && h[i] != h[j]) {
          vector<int> a = {h[i], h[j], h[h[j]+j]};
          vector<int> b = {j-i, h[j], h[j]+j-i};
          sort(a.begin(), a.end());
          sort(b.begin(), b.end());
          
          if (a == b) res++;
        }
      }

      if (abs(h[i]-h[j])+j < n && h[i] != abs(h[i]-h[j]) && h[j] != abs(h[i]-h[j])) {
        vector<int> a = {h[i], h[j], h[abs(h[i]-h[j])+j]};
        vector<int> b = {j-i, abs(h[i]-h[j]), abs(h[i]-h[j])+j-i};
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        
        if (a == b) res++;
      }
    }
  }

  return res;
}

std::vector<int> construct_range(int M, int K) {
  vector<int> ans(M);
  for (int i = 0; i < M; i++) {
    if (i % 3 <= 1) ans[i] = 1;
    else ans[i] = 2;
  }

  return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

triples.cpp: In function 'long long int count_triples(std::vector<int>)':
triples.cpp:91:22: error: 'j' was not declared in this scope
   91 |       if (abs(h[i]-h[j])+j < n && h[i] != abs(h[i]-h[j]) && h[j] != abs(h[i]-h[j])) {
      |                      ^
triples.cpp:92:57: error: could not convert '{h.std::vector<int>::operator[](((std::vector<int>::size_type)i)), <expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   92 |         vector<int> a = {h[i], h[j], h[abs(h[i]-h[j])+j]};
      |                                                         ^
      |                                                         |
      |                                                         <brace-enclosed initializer list>
triples.cpp:93:65: error: could not convert '{<expression error>, <expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   93 |         vector<int> b = {j-i, abs(h[i]-h[j]), abs(h[i]-h[j])+j-i};
      |                                                                 ^
      |                                                                 |
      |                                                                 <brace-enclosed initializer list>