답안 #6147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6147 2014-06-20T14:03:09 Z gs13068 한자 끝말잇기 (JOI14_kanji) C++
0 / 100
216 ms 11732 KB
#include "Annalib.h"
#include<algorithm>

static long long D[300][300];
static long long G[60];
static int Y[60];

void Anna(int N,int M,int A[],int B[],long long C[],int Q,int S[],int T[],int K,int U[])
{
  long long val=0,mul=1;
  int i,j,k,l;
  for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=4e18;
  for(i=0;i<M;i++)
  {
    for(j=0;j<K;j++)if(i==U[j])break;
    if(j==K)D[A[i]][B[i]]=C[i];
  }
  for(i=0;i<N;i++)D[i][i]=0;
  for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];

  for(i=0;i<Q;i++)Y[i]=K;
  for(i=0;i<K;i++)
  {
    for(j=0;j<i;j++)
    {
      l=0;
      for(k=0;k<Q;k++)if(Y[k]==j)
      {
        G[l]=D[B[U[i]]][T[k]]-D[B[U[j]]][T[k]];
        if(G[l]<-C[U[i]]+C[U[j]])Y[k]=i;
        l++;
      }
      if(l==0)continue;
      std::sort(G,G+l);
      k=std::lower_bound(G,G+l,-C[U[i]]+C[U[j]])-G;
      val+=k*mul;
      mul*=l;
    }
    l=0;
    for(k=0;k<Q;k++)if(Y[k]==K)
    {
      G[l]=D[S[k]][A[U[i]]]+D[B[U[i]]][T[k]]-D[S[k]][T[k]];
      if(G[l]<0)Y[k]=i;
      l++;
    }
    if(l==0)continue;
    std::sort(G,G+l);
    k=std::lower_bound(G,G+1,-C[U[i]])-G;
    val+=k*mul;
    mul*=l;
  }
  while(val)
  {
    Tap(val&1);
    val>>=1;
  }
}
#include "Brunolib.h"
#include<algorithm>

static long long D[300][300];
static int V[300][300];
static std::pair<long long,int> G[60];
static int Y[60];

static void answer(int i,int j)
{
  if(V[i][j]>0)Answer(V[i][j]-1);
  if(V[i][j]<0)
  {
    answer(i,-V[i][j]-1);
    answer(-V[i][j]-1,j);
  }
}

void Bruno(int N,int M,int A[],int B[],long long C[],int Q,int S[],int T[],int K,int U[],int L,int X[])
{
  long long val=0,mul=1;
  int i,j,k,l,p;
  for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=4e18;
  for(i=0;i<M;i++)if(C[i]>0)
  {
    D[A[i]][B[i]]=C[i];
    V[A[i]][B[i]]=i+1;
  }
  for(i=0;i<N;i++)
  {
    D[i][i]=0;
    V[i][i]=0;
  }
  for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)if(D[i][j]>D[i][k]+D[k][j])
  {
    D[i][j]=D[i][k]+D[k][j];
    V[i][j]=-k-1;
  }

  for(i=0;i<L;i++)
  {
    val+=X[i]*mul;
    mul<<=1;
  }
  for(i=0;i<Q;i++)Y[i]=K;
  for(i=0;i<K;i++)
  {
    for(j=0;j<i;j++)
    {
      l=0;
      for(k=0;k<Q;k++)if(Y[k]==j)
      {
        G[l].first=D[B[U[i]]][T[k]]-D[B[U[j]]][T[k]];
        G[l].second=k;
        l++;
      }
      if(l==0)continue;
      std::sort(G,G+l);
      for(k=0;k<val%l;k++)Y[G[k].second]=i;
      val/=l;
    }
    l=0;
    for(k=0;k<Q;k++)if(Y[k]==K)
    {
      G[l].first=D[S[k]][A[U[i]]]+D[B[U[i]]][T[k]]-D[S[k]][T[k]];
      G[l].second=k;
      l++;
    }
    if(l==0)continue;
    std::sort(G,G+l);
    for(k=0;k<val%l;k++)Y[G[k].second]=i;
    val/=l;
  }
  for(i=0;i<Q;i++)
  {
    if(Y[i]==K)answer(S[i],T[i]);
    else
    {
      answer(S[i],A[U[Y[i]]]);
      Answer(U[Y[i]]);
      answer(B[U[Y[i]]],T[i]);
    }
    Answer(-1);
  }
}

Compilation message

Bruno.cpp: In function 'void Bruno(int, int, int*, int*, long long int*, int, int*, int*, int, int*, int, int*)':
Bruno.cpp:22:15: warning: unused variable 'p' [-Wunused-variable]
   int i,j,k,l,p;
               ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 11732 KB Output isn't correct - Wrong Answer [9]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 11732 KB Output isn't correct - Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 11732 KB Output isn't correct - Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 11732 KB Output isn't correct - Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 11732 KB Output isn't correct - Wrong Answer [6]
2 Incorrect 58 ms 11732 KB Output isn't correct - Wrong Answer [6]
3 Incorrect 52 ms 11732 KB Output isn't correct - Wrong Answer [6]
4 Incorrect 72 ms 11732 KB Output isn't correct - Wrong Answer [8]
5 Incorrect 69 ms 11732 KB Output isn't correct - Wrong Answer [8]
6 Incorrect 62 ms 11732 KB Output isn't correct - Wrong Answer [9]
7 Correct 62 ms 11732 KB Output is correct - L = 1
8 Correct 62 ms 11732 KB Output is correct - L = 1
9 Incorrect 58 ms 11732 KB Output isn't correct - Wrong Answer [9]
10 Incorrect 58 ms 11732 KB Output isn't correct - Wrong Answer [9]
11 Incorrect 62 ms 11732 KB Output isn't correct - Wrong Answer [9]
12 Correct 52 ms 11732 KB Output is correct - L = 0
13 Correct 216 ms 11732 KB Output is correct - L = 0
14 Incorrect 72 ms 11732 KB Output isn't correct - Wrong Answer [8]
15 Incorrect 65 ms 11732 KB Output isn't correct - Wrong Answer [9]
16 Incorrect 69 ms 11732 KB Output isn't correct - Wrong Answer [9]
17 Incorrect 86 ms 11732 KB Output isn't correct - Wrong Answer [9]
18 Incorrect 88 ms 11732 KB Output isn't correct - Wrong Answer [9]
19 Incorrect 65 ms 11732 KB Output isn't correct - Wrong Answer [6]
20 Correct 72 ms 11732 KB Output is correct - L = 0
21 Correct 89 ms 11732 KB Output is correct - L = 0
22 Incorrect 69 ms 11732 KB Output isn't correct - Wrong Answer [9]
23 Incorrect 75 ms 11732 KB Output isn't correct - Wrong Answer [9]
24 Incorrect 78 ms 11732 KB Output isn't correct - Wrong Answer [9]