Submission #6150

# Submission time Handle Problem Language Result Execution time Memory
6150 2014-06-20T14:28:39 Z gs13068 한자 끝말잇기 (JOI14_kanji) C++
100 / 100
225 ms 11732 KB
#include "Annalib.h"
#include<algorithm>
#include<cstdio>

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++;
      }
      std::sort(G,G+l);
      k=std::lower_bound(G,G+l,-C[U[i]]+C[U[j]])-G;
      val+=k*mul;
      mul*=l+1;
    }
    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]<-C[U[i]])Y[k]=i;
      l++;
    }
    std::sort(G,G+l);
    k=std::lower_bound(G,G+l,-C[U[i]])-G;
    val+=k*mul;
    mul*=l+1;
  }
  while(val)
  {
    Tap(val&1);
    val>>=1;
  }
}
#include "Brunolib.h"
#include<algorithm>
#include<cstdio>

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++;
      }
      std::sort(G,G+l);
      for(k=0;k<val%(l+1);k++)Y[G[k].second]=i;
      val/=l+1;
    }
    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++;
    }
    std::sort(G,G+l);
    for(k=0;k<val%(l+1);k++)Y[G[k].second]=i;
    val/=l+1;
  }
  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:23:15: warning: unused variable 'p' [-Wunused-variable]
   int i,j,k,l,p;
               ^
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11732 KB Output is correct - L = 23
2 Correct 62 ms 11732 KB Output is correct - L = 22
3 Correct 65 ms 11732 KB Output is correct - L = 4
4 Correct 58 ms 11732 KB Output is correct - L = 24
5 Correct 58 ms 11732 KB Output is correct - L = 24
6 Correct 55 ms 11732 KB Output is correct - L = 21
7 Correct 62 ms 11732 KB Output is correct - L = 17
8 Correct 58 ms 11732 KB Output is correct - L = 4
9 Correct 78 ms 11732 KB Output is correct - L = 7
10 Correct 92 ms 11732 KB Output is correct - L = 4
11 Correct 58 ms 11732 KB Output is correct - L = 5
12 Correct 225 ms 11732 KB Output is correct - L = 0
13 Correct 55 ms 11732 KB Output is correct - L = 10
14 Correct 62 ms 11732 KB Output is correct - L = 0
# Verdict Execution time Memory Grader output
1 Correct 68 ms 11732 KB Output is correct - L = 60
2 Correct 58 ms 11732 KB Output is correct - L = 59
3 Correct 55 ms 11732 KB Output is correct - L = 4
4 Correct 58 ms 11732 KB Output is correct - L = 39
5 Correct 62 ms 11732 KB Output is correct - L = 60
6 Correct 55 ms 11732 KB Output is correct - L = 59
7 Correct 65 ms 11732 KB Output is correct - L = 1
8 Correct 62 ms 11732 KB Output is correct - L = 1
9 Correct 62 ms 11732 KB Output is correct - L = 61
10 Correct 58 ms 11732 KB Output is correct - L = 61
11 Correct 68 ms 11732 KB Output is correct - L = 61
12 Correct 75 ms 11732 KB Output is correct - L = 0
13 Correct 222 ms 11732 KB Output is correct - L = 0
14 Correct 58 ms 11732 KB Output is correct - L = 59
15 Correct 62 ms 11732 KB Output is correct - L = 9
16 Correct 72 ms 11732 KB Output is correct - L = 22
17 Correct 89 ms 11732 KB Output is correct - L = 20
18 Correct 89 ms 11732 KB Output is correct - L = 37
19 Correct 69 ms 11732 KB Output is correct - L = 36
20 Correct 72 ms 11732 KB Output is correct - L = 0
21 Correct 89 ms 11732 KB Output is correct - L = 0
22 Correct 69 ms 11732 KB Output is correct - L = 61
23 Correct 55 ms 11732 KB Output is correct - L = 60
24 Correct 55 ms 11732 KB Output is correct - L = 62
# Verdict Execution time Memory Grader output
1 Correct 62 ms 11732 KB Output is correct - L = 60
2 Correct 55 ms 11732 KB Output is correct - L = 59
3 Correct 66 ms 11732 KB Output is correct - L = 4
4 Correct 59 ms 11732 KB Output is correct - L = 39
5 Correct 72 ms 11732 KB Output is correct - L = 60
6 Correct 58 ms 11732 KB Output is correct - L = 59
7 Correct 59 ms 11732 KB Output is correct - L = 1
8 Correct 68 ms 11732 KB Output is correct - L = 1
9 Correct 62 ms 11732 KB Output is correct - L = 61
10 Correct 52 ms 11732 KB Output is correct - L = 61
11 Correct 58 ms 11732 KB Output is correct - L = 61
12 Correct 66 ms 11732 KB Output is correct - L = 0
13 Correct 205 ms 11732 KB Output is correct - L = 0
14 Correct 62 ms 11732 KB Output is correct - L = 59
15 Correct 58 ms 11732 KB Output is correct - L = 9
16 Correct 86 ms 11732 KB Output is correct - L = 22
17 Correct 81 ms 11732 KB Output is correct - L = 20
18 Correct 76 ms 11732 KB Output is correct - L = 37
19 Correct 59 ms 11732 KB Output is correct - L = 36
20 Correct 75 ms 11732 KB Output is correct - L = 0
21 Correct 81 ms 11732 KB Output is correct - L = 0
22 Correct 55 ms 11732 KB Output is correct - L = 61
23 Correct 52 ms 11732 KB Output is correct - L = 60
24 Correct 55 ms 11732 KB Output is correct - L = 62
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11732 KB Output is correct - L = 60
2 Correct 55 ms 11732 KB Output is correct - L = 59
3 Correct 65 ms 11732 KB Output is correct - L = 4
4 Correct 65 ms 11732 KB Output is correct - L = 39
5 Correct 58 ms 11732 KB Output is correct - L = 60
6 Correct 58 ms 11732 KB Output is correct - L = 59
7 Correct 62 ms 11732 KB Output is correct - L = 1
8 Correct 62 ms 11732 KB Output is correct - L = 1
9 Correct 52 ms 11732 KB Output is correct - L = 61
10 Correct 58 ms 11732 KB Output is correct - L = 61
11 Correct 55 ms 11732 KB Output is correct - L = 61
12 Correct 55 ms 11732 KB Output is correct - L = 0
13 Correct 198 ms 11732 KB Output is correct - L = 0
14 Correct 55 ms 11732 KB Output is correct - L = 59
15 Correct 58 ms 11732 KB Output is correct - L = 9
16 Correct 72 ms 11732 KB Output is correct - L = 22
17 Correct 78 ms 11732 KB Output is correct - L = 20
18 Correct 78 ms 11732 KB Output is correct - L = 37
19 Correct 55 ms 11732 KB Output is correct - L = 36
20 Correct 66 ms 11732 KB Output is correct - L = 0
21 Correct 89 ms 11732 KB Output is correct - L = 0
22 Correct 55 ms 11732 KB Output is correct - L = 61
23 Correct 55 ms 11732 KB Output is correct - L = 60
24 Correct 55 ms 11732 KB Output is correct - L = 62
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11732 KB Output is correct - L = 60
2 Correct 62 ms 11732 KB Output is correct - L = 59
3 Correct 52 ms 11732 KB Output is correct - L = 4
4 Correct 55 ms 11732 KB Output is correct - L = 39
5 Correct 55 ms 11732 KB Output is correct - L = 60
6 Correct 62 ms 11732 KB Output is correct - L = 59
7 Correct 66 ms 11732 KB Output is correct - L = 1
8 Correct 68 ms 11732 KB Output is correct - L = 1
9 Correct 62 ms 11732 KB Output is correct - L = 61
10 Correct 65 ms 11732 KB Output is correct - L = 61
11 Correct 55 ms 11732 KB Output is correct - L = 61
12 Correct 62 ms 11732 KB Output is correct - L = 0
13 Correct 195 ms 11732 KB Output is correct - L = 0
14 Correct 66 ms 11732 KB Output is correct - L = 59
15 Correct 55 ms 11732 KB Output is correct - L = 9
16 Correct 72 ms 11732 KB Output is correct - L = 22
17 Correct 84 ms 11732 KB Output is correct - L = 20
18 Correct 84 ms 11732 KB Output is correct - L = 37
19 Correct 58 ms 11732 KB Output is correct - L = 36
20 Correct 72 ms 11732 KB Output is correct - L = 0
21 Correct 86 ms 11732 KB Output is correct - L = 0
22 Correct 68 ms 11732 KB Output is correct - L = 61
23 Correct 58 ms 11732 KB Output is correct - L = 60
24 Correct 55 ms 11732 KB Output is correct - L = 62