답안 #223225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223225 2020-04-15T05:36:11 Z rainy Trener (COCI20_trener) C++14
55 / 110
2000 ms 24536 KB
#include<bits/stdc++.h>
#define INF 2123456789
#define BINF 9123456789123456789
#define pb push_back
#define MAXN 55
#define MAXK 1505
//#define DB
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<pl> vpl;
typedef pair<ii,ii>pii;
typedef vector<pii> vpii;
int N,K;
char s[MAXN][MAXK][MAXN];
map<ii,set<ii> >al;
map<ii,int>nw;

int main(){
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            scanf(" %s",&s[i][j]);
            #ifdef DB
            // printf("%d %d: %s\n",i,j,s[i][j]);
            #endif // DB
        }
    }
    for(int i=N-1;i>0;i--){ // highest N row
        for(int j=0;j<K;j++){ // for each surname in high N row
            for(int k=0;k<K;k++){  // for each surname in low N row
                #ifdef DB
                //printf("----\n%s, %s\n",s[i][j],s[i-1][k]);
                #endif // DB
                bool sub=false;
                for(int l=0;l<2;l++){  // for each letter in high N row
                    bool tmp=true;
                    for(int m=0;m<=i-1;m++){ // for each letter in low N row
                        if(s[i][j][l+m]!=s[i-1][k][m]){
                            //printf("%d = %c X %d = %c\n",l,s[i][j][l],m,s[i-1][k][m]);
                            tmp=false;
                            break;
                        }
                        //printf("%d = %c | %d = %c\n",l,s[i][j][l],m,s[i-1][k][m]);
                    }
                    if(tmp){sub=true;break;}
                }
                if(sub){
                    #ifdef DB
                    printf("%s -- %s\n",s[i][j],s[i-1][k]);
                    #endif // DB
                    al[ii(i-1,k)].insert(ii(i,j));
                }
            }
        }
    }
    for(int i=0;i<K;i++)nw[ii(0,i)]=1;
    for(int i=0;i<N-1;i++){ // lower N row
        for(int j=0;j<K;j++){ // lower
            for(int k=0;k<K;k++){ // higher
                if(al[ii(i,j)].count(ii(i+1,k)))
                    nw[ii(i+1,k)]=(nw[ii(i+1,k)]+nw[ii(i,j)])%MOD;
            }
        }
    }
    #ifdef DB
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            printf("(%d, %d)\t%s\t%d\n",i,j,s[i][j],nw[ii(i,j)]);
        }
    }
    #endif // DB
    int ans=0;
    for(int i=0;i<K;i++){
        ans=(ans+nw[ii(N-1,i)])%MOD;
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message

trener.cpp: In function 'int main()':
trener.cpp:28:33: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[55]' [-Wformat=]
             scanf(" %s",&s[i][j]);
                         ~~~~~~~~^
trener.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&K);
     ~~~~~^~~~~~~~~~~~~~
trener.cpp:28:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %s",&s[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1792 KB Output is correct
2 Correct 24 ms 1792 KB Output is correct
3 Correct 24 ms 1792 KB Output is correct
4 Correct 263 ms 24536 KB Output is correct
5 Correct 40 ms 2680 KB Output is correct
6 Correct 38 ms 2680 KB Output is correct
7 Correct 209 ms 24440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 24 ms 1792 KB Output is correct
6 Correct 24 ms 1792 KB Output is correct
7 Correct 24 ms 1792 KB Output is correct
8 Correct 263 ms 24536 KB Output is correct
9 Correct 40 ms 2680 KB Output is correct
10 Correct 38 ms 2680 KB Output is correct
11 Correct 209 ms 24440 KB Output is correct
12 Execution timed out 2083 ms 23748 KB Time limit exceeded
13 Halted 0 ms 0 KB -