提出 #67768


ソースコード 拡げる

// include {{{
#include <cstdio>
#include <iostream>
//#include <sstream>
#include <string>
#include <vector>
//#include <deque>
#include <stack>
#include <queue>
//#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <numeric>
//#include <complex>
// }}}
using namespace std;
// macro {{{
typedef long long ll;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,j,k) for(int i=j;i<(k);++i)
//#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define priority_queue_greater(T) priority_queue< T, vector<T>, greater<T> >
#define F first
#define S second
//test define...
#define D(x) #x<<"="<<(x)
#define CC <<" "<<
#define CE <<endl;
// }}}

string first,last;
int n;
int main(){
  while( cin >> first >> last >> n ){
    int size = first.size();
    int N = n+2;
    vector<string> s(N);
    s[0] = first;
    s[n+1] = last;
    rep(i,n){ cin >> s[i+1]; }

    mat edges(N);
    rep(i,N)REP(j,i+1,N){
      int diff = 0;
      rep(k,size)if( s[i][k] != s[j][k] ){ diff++; }
      if( diff <= 1 ){
        edges[i].push_back(j);
        edges[j].push_back(i);
      }
    }

    vec memo(N, -1);
    queue<int> qn, qp;
    qn.push(0);
    qp.push(-2);
    while( !qn.empty() ){
      int now = qn.front(); qn.pop();
      int prev= qp.front(); qp.pop();

      if( memo[now] != -1 ){ continue; }
      memo[now] = prev;
      if( now == N-1 ){ break; }

      int len = edges[now].size();
      rep(i,len){
        int next = edges[now][i];
        if( memo[next] == -1 ){
          qn.push( next );
          qp.push( now );
        }
      }
    }

    if( memo[n+1] == -1 ){
      cout << -1 << endl;
    }else{
      int sum = -2;
      int now = n+1;
      vector<string> ans;
      while( now != -2 ){
        sum++;
        ans.push_back( s[now] );
        now = memo[now];
      }
      cout << sum << endl;
      for(int i=ans.size()-1; i>=0; i--){
        cout << ans[i] << endl;
      }
    }
  }
  return 0;
}

提出情報

提出日時
問題 C - ダブレット
ユーザ jimon
言語 C++ (G++ 4.6.4)
得点 100
コード長 2234 Byte
結果 AC
実行時間 90 ms
メモリ 8892 KiB

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 86
セット名 テストケース
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_rand_00.txt, 01_rand_01.txt, 01_rand_02.txt, 01_rand_03.txt, 01_rand_04.txt, 01_rand_05.txt, 01_rand_06.txt, 01_rand_07.txt, 01_rand_08.txt, 01_rand_09.txt, 01_rand_10.txt, 01_rand_11.txt, 01_rand_12.txt, 01_rand_13.txt, 01_rand_14.txt, 01_rand_15.txt, 01_rand_16.txt, 01_rand_17.txt, 01_rand_18.txt, 01_rand_19.txt, 02_maxrand_00.txt, 02_maxrand_01.txt, 02_maxrand_02.txt, 02_maxrand_03.txt, 02_maxrand_04.txt, 02_maxrand_05.txt, 02_maxrand_06.txt, 02_maxrand_07.txt, 02_maxrand_08.txt, 02_maxrand_09.txt, 02_maxrand_10.txt, 02_maxrand_11.txt, 02_maxrand_12.txt, 02_maxrand_13.txt, 02_maxrand_14.txt, 02_maxrand_15.txt, 02_maxrand_16.txt, 02_maxrand_17.txt, 02_maxrand_18.txt, 02_maxrand_19.txt, 03_long_00.txt, 03_long_01.txt, 03_long_02.txt, 03_long_03.txt, 03_long_04.txt, 03_long_05.txt, 03_long_06.txt, 03_long_07.txt, 03_long_08.txt, 03_long_09.txt, 03_long_10.txt, 03_long_11.txt, 03_long_12.txt, 03_long_13.txt, 03_long_14.txt, 03_long_15.txt, 03_long_16.txt, 03_long_17.txt, 03_long_18.txt, 03_long_19.txt, 04_manygroup_00.txt, 04_manygroup_01.txt, 04_manygroup_02.txt, 04_manygroup_03.txt, 04_manygroup_04.txt, 04_manygroup_05.txt, 04_manygroup_06.txt, 04_manygroup_07.txt, 04_manygroup_08.txt, 04_manygroup_09.txt, 04_manygroup_10.txt, 04_manygroup_11.txt, 04_manygroup_12.txt, 04_manygroup_13.txt, 04_manygroup_14.txt, 04_manygroup_15.txt, 04_manygroup_16.txt, 04_manygroup_17.txt, 04_manygroup_18.txt, 04_manygroup_19.txt, 10_min_01.txt, 10_min_02.txt, 10_min_03.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 20 ms 792 KiB
00_sample_02.txt AC 19 ms 772 KiB
00_sample_03.txt AC 20 ms 676 KiB
01_rand_00.txt AC 70 ms 916 KiB
01_rand_01.txt AC 21 ms 688 KiB
01_rand_02.txt AC 57 ms 832 KiB
01_rand_03.txt AC 21 ms 1264 KiB
01_rand_04.txt AC 28 ms 780 KiB
01_rand_05.txt AC 20 ms 784 KiB
01_rand_06.txt AC 35 ms 816 KiB
01_rand_07.txt AC 29 ms 788 KiB
01_rand_08.txt AC 21 ms 820 KiB
01_rand_09.txt AC 32 ms 792 KiB
01_rand_10.txt AC 51 ms 824 KiB
01_rand_11.txt AC 88 ms 948 KiB
01_rand_12.txt AC 43 ms 820 KiB
01_rand_13.txt AC 56 ms 824 KiB
01_rand_14.txt AC 46 ms 8372 KiB
01_rand_15.txt AC 26 ms 696 KiB
01_rand_16.txt AC 43 ms 7484 KiB
01_rand_17.txt AC 31 ms 812 KiB
01_rand_18.txt AC 20 ms 784 KiB
01_rand_19.txt AC 44 ms 820 KiB
02_maxrand_00.txt AC 74 ms 920 KiB
02_maxrand_01.txt AC 83 ms 912 KiB
02_maxrand_02.txt AC 48 ms 8892 KiB
02_maxrand_03.txt AC 90 ms 816 KiB
02_maxrand_04.txt AC 33 ms 904 KiB
02_maxrand_05.txt AC 63 ms 828 KiB
02_maxrand_06.txt AC 78 ms 916 KiB
02_maxrand_07.txt AC 82 ms 912 KiB
02_maxrand_08.txt AC 90 ms 912 KiB
02_maxrand_09.txt AC 55 ms 928 KiB
02_maxrand_10.txt AC 86 ms 916 KiB
02_maxrand_11.txt AC 65 ms 924 KiB
02_maxrand_12.txt AC 71 ms 924 KiB
02_maxrand_13.txt AC 60 ms 912 KiB
02_maxrand_14.txt AC 63 ms 916 KiB
02_maxrand_15.txt AC 73 ms 940 KiB
02_maxrand_16.txt AC 85 ms 912 KiB
02_maxrand_17.txt AC 29 ms 1416 KiB
02_maxrand_18.txt AC 55 ms 912 KiB
02_maxrand_19.txt AC 30 ms 920 KiB
03_long_00.txt AC 77 ms 948 KiB
03_long_01.txt AC 68 ms 948 KiB
03_long_02.txt AC 35 ms 828 KiB
03_long_03.txt AC 35 ms 824 KiB
03_long_04.txt AC 51 ms 828 KiB
03_long_05.txt AC 43 ms 820 KiB
03_long_06.txt AC 30 ms 1552 KiB
03_long_07.txt AC 50 ms 820 KiB
03_long_08.txt AC 47 ms 832 KiB
03_long_09.txt AC 49 ms 796 KiB
03_long_10.txt AC 47 ms 816 KiB
03_long_11.txt AC 75 ms 948 KiB
03_long_12.txt AC 48 ms 8892 KiB
03_long_13.txt AC 28 ms 920 KiB
03_long_14.txt AC 66 ms 944 KiB
03_long_15.txt AC 73 ms 948 KiB
03_long_16.txt AC 54 ms 928 KiB
03_long_17.txt AC 36 ms 828 KiB
03_long_18.txt AC 33 ms 788 KiB
03_long_19.txt AC 40 ms 824 KiB
04_manygroup_00.txt AC 74 ms 916 KiB
04_manygroup_01.txt AC 85 ms 916 KiB
04_manygroup_02.txt AC 44 ms 828 KiB
04_manygroup_03.txt AC 49 ms 836 KiB
04_manygroup_04.txt AC 65 ms 820 KiB
04_manygroup_05.txt AC 62 ms 916 KiB
04_manygroup_06.txt AC 34 ms 828 KiB
04_manygroup_07.txt AC 48 ms 824 KiB
04_manygroup_08.txt AC 44 ms 912 KiB
04_manygroup_09.txt AC 39 ms 820 KiB
04_manygroup_10.txt AC 85 ms 908 KiB
04_manygroup_11.txt AC 78 ms 912 KiB
04_manygroup_12.txt AC 76 ms 944 KiB
04_manygroup_13.txt AC 62 ms 912 KiB
04_manygroup_14.txt AC 76 ms 948 KiB
04_manygroup_15.txt AC 85 ms 924 KiB
04_manygroup_16.txt AC 88 ms 816 KiB
04_manygroup_17.txt AC 51 ms 828 KiB
04_manygroup_18.txt AC 89 ms 920 KiB
04_manygroup_19.txt AC 87 ms 916 KiB
10_min_01.txt AC 19 ms 784 KiB
10_min_02.txt AC 20 ms 792 KiB
10_min_03.txt AC 19 ms 780 KiB