Submission #1249920

#TimeUsernameProblemLanguageResultExecution timeMemory
1249920Jakub_WozniakTriple Peaks (IOI25_triples)C++20
7.43 / 100
1300 ms2736 KiB
#include "triples.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<vector <int> ,ll> pvl;
#define st first
#define nd second


vector<int> construct_range(int M, int K)
{
    vector <int> res(M,0);
    int s = M/2;
    res[s] = 1;
    int licz = 1;
    for(int i = s-1 ; i >= 0 ; i-=2)
    {
        res[i] = licz+1;
        if(i-1 >= 0)res[i-1] = licz; 
        licz += 2;
    }
    licz = 1;
    for(int i = s+1 ; i < M ; i+=2)
    {
        res[i] = licz+1;
        if(i < M)res[i+1] = licz; 
        licz += 2;
    }

    return res;
}

long long count_triplesnd(vector<int> H) 
{
  int N = H.size();
  ll ile = 0;
  for(int i = N-1 ; i >= 0 ; i--)
  {
    int k = i-H[i];
    if(k < 0)continue;
    int j = k+H[k];
    if(j < 0 || j >= N);
    else if(H[k]+H[j] == H[i] && (i-j) == H[j] && k < j && j < i)ile++;
    j = i-H[k];
    if(j < 0 || j >= N);
    else if(H[k]+H[j] == H[i] && (j-k) == H[j] && k < j && j < i)ile++;
  }
  return ile;
}

long long count_triples(vector<int> H) 
{
  int N = H.size();
  int B = 0;
  bool czynd = 1;
  for(int i = 0; i < N ; i++)B = max(B , H[i]);

  for(int i = 1; i < N ; i++)
  {
    if(H[i-1] > H[i])czynd = 0;
  }

  if(czynd)return count_triplesnd(H);

  ll ile = 0;
  for(int i = 0 ; i < N ; i++)
  {
    for(int j = i+1 ; j < min(N,i+B+1) ; j++)
    {
      int d = j-i;
      if(H[i] == d || H[j] == d)
      {
        int R = 0;
        if(H[i]  == d)R = H[j];
        else R = H[i];
        int k = j+R;
        if(k >= 0 && k < N && k > j && H[k] == R+d)ile++;
        k = i+R;
        if(k >= 0 && k < N && k > j && R == H[k]+d)ile++;
      }
      else
      {
        int k = j+min(H[i] , H[j]);
        if(k >= 0 && k < N && H[k] == d && min(H[i],H[j])+d == max(H[i],H[j]))ile++;
      }
    }
  }
  return ile;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...