답안 #141158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141158 2019-08-07T04:44:54 Z babo 비밀 (JOI14_secret) C++14
컴파일 오류
0 ms 0 KB
//#include "secret.h"
#include <bits/stdc++.h>

void Init(int N, int A[]);
int Query(int L, int R);

int Secret(int X, int Y);

int tr[20][2020];
int a[2020];
int n;

void bin(int now,int s,int e){
	int i,sum;
	int mid=(s+e)/2;
	for(i=mid,sum=a[mid];i<e;i++)
	{
		tr[now][i]=sum;
		if(i+1<e)
			sum=Secret(sum,a[i+1]);
	}
	for(i=mid-1,sum=a[mid-1];i>=s;i--)
	{
		tr[now][i]=sum;
		if(i-1>=s)
			sum=Secret(a[i-1],sum);
	}

	if(e<=s+2)
		return;
	bin(now+1,s,mid);
	bin(now+1,mid,e);
}

void Init(int N,int A[]){
	n=N;
	for(int i=0;i<n;i++)
		a[i]=A[i];
	bin(1,0,n);
	/*for(int i=1;i<=9;i++)
	{
		for(int j=0;j<N;j++)
		{
			printf("%d ",tr[i][j]);
		}
		puts("");
	}*/

}

int bin2(int now,int s,int e,int l,int r){
	int mid=(s+e)/2;
	if(s>r||e<l) return -1;
	if(l<=mid&&r>=mid)
	{
		if(l==mid) return tr[now][r-1];
		if(r==mid) return tr[now][l];
		return Secret(tr[now][l],tr[now][r-1]);
	}
	int temp1=bin2(now+1,s,mid,l,r);
	int temp2=bin2(now+1,mid,e,l,r);
	//printf("%d %d %d %d %d: %d\n",now,s,e,l,r,temp1==-1?temp2:temp1);
	if(temp1==-1) return temp2;
	return temp1;
}


int Query(int l,int r){
	return bin2(1,0,n,l,r+1);
}


#include <stdio.h>
#include <stdlib.h>

#define MAX_N                  1000
#define MAX_Q                 10000
#define MAX_VALUE        1000000000

static int N;
static int A[MAX_N];
static int Q;
static int L[MAX_Q];
static int R[MAX_Q];

static int secret_count;

int Secret(int X, int Y) {
  ++secret_count;
  if (!(0 <= X && X <= MAX_VALUE)) {
    fprintf(stderr, "Wrong Answer [1]\n");
    exit(0);
  }
  if (!(0 <= Y && Y <= MAX_VALUE)) {
    fprintf(stderr, "Wrong Answer [1]\n");
    exit(0);
  }
  return X*Y>MAX_VALUE?MAX_VALUE:X*Y;
  return (X + 2 * (Y / 2) < MAX_VALUE) ? (X + 2 * (Y / 2)) : MAX_VALUE;
}

int main() {
  int i, j;
  int secret_count_by_init;
  int max_secret_count_by_query = 0;

  if (1 != scanf("%d", &N)) {
    fprintf(stderr, "error: cannot read N.\n");
    exit(1);
  }
  if (!(1 <= N && N <= MAX_N)) {
    fprintf(stderr, "error: N is out of bounds.\n");
    exit(1);
  }
  for (i = 0; i < N; ++i) {
    if (1 != scanf("%d", &A[i])) {
      fprintf(stderr, "error: cannot read A[%d].\n", i);
      exit(1);
    }
    if (!(0 <= A[i] && A[i] <= MAX_VALUE)) {
      fprintf(stderr, "error: A[%d] is out of bounds.\n", i);
      exit(1);
    }
  }
  if (1 != scanf("%d", &Q)) {
    fprintf(stderr, "error: cannot read Q.\n");
    exit(1);
  }
  if (!(0 <= Q && Q <= MAX_Q)) {
    fprintf(stderr, "error: Q is out of bounds.\n");
    exit(1);
  }
  for (j = 0; j < Q; ++j) {
    if (2 != scanf("%d%d", &L[j], &R[j])) {
      fprintf(stderr, "error: cannot read L[%d] and R[%d].\n", j, j);
      exit(1);
    }
    if (!(0 <= L[j] && L[j] <= R[j] && R[j] <= N - 1)) {
      fprintf(stderr,
              "error: L[%d] and R[%d] do not satisfy the constraints.\n",
              j, j);
      exit(1);
    }
  }

  secret_count = 0;
  Init(N, A);
  secret_count_by_init = secret_count;

  for (j = 0; j < Q; ++j) {
    secret_count = 0;
    printf("%d\n", Query(L[j], R[j]));
    if (max_secret_count_by_query < secret_count) {
      max_secret_count_by_query = secret_count;
    }
  }

  fprintf(stderr, "number of calls to Secret by Init : %d\n",
          secret_count_by_init);
  fprintf(stderr, "maximum number of calls to Secret by Query : %d\n",
          max_secret_count_by_query);

  return 0;
}

Compilation message

/tmp/ccuqnJqz.o: In function `Secret(int, int)':
secret.cpp:(.text+0x0): multiple definition of `Secret(int, int)'
/tmp/cc3i1TdC.o:grader-full.cpp:(.text+0x2c0): first defined here
/tmp/ccuqnJqz.o: In function `main':
secret.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc3i1TdC.o:grader-full.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status