Submission #570044


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int lcs(string s,string s2,int len) {
	int c[len+1][len+1];	
	int m = s.size();
	int n = s2.size();

	int ret = 0;
	s = ' ' + s;
	s2 = ' ' + s2;

	REP(i,1,m+1) c[i][0] = 0;
	REP(j,1,n+1) c[0][j] = 0;

	REP(i,1,m+1) {
		REP(j,1,n+1) {
			if(s[i] == s2[j]) c[i][j] = c[i-1][j-1] + 1;
			else c[i][j] = max(c[i-1][j],c[i][j-1]);
			ret = max(ret,c[i][j]);
	    }
    }

	return ret;
}

int main() {
	int n;
	cin >> n;

	string s;
	cin >> s;

	int ans = n;
	REP(i, 1, n) {
		string a = s.substr(0, i);
		string b = s.substr(i);

		// cout << a << " " << b << endl;
		// cout << lcs(a, b, 100) << endl;
		//
		int t = lcs(a, b, 100);
		int t2 = n - 2*t;
		ans = min(ans, t2);
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task D - ヘイホー君と削除
User Ry0u_
Language C++ (GCC 4.9.2)
Score 100
Code Size 1131 Byte
Status AC
Exec Time 32 ms
Memory 932 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 88
Set Name Test Cases
Sample test_abacbabc.txt, test_abababab.txt, test_abcde.txt, test_26_codefestiv.txt
All test_100_bbaaababba.txt, test_100_bcbcbbccbc.txt, test_100_cccdcddccd.txt, test_100_dddccddccd.txt, test_100_kkkkjkkjkj.txt, test_100_lllklkkllk.txt, test_100_nooooonnnn.txt, test_100_prpttrstrs.txt, test_100_psupruuutq.txt, test_100_qpuutstspt.txt, test_100_qstsustsus.txt, test_100_qtrqqsqqup.txt, test_100_tpqqqrrrsp.txt, test_100_tsrrtqrqtt.txt, test_100_tussuutruq.txt, test_100_ussuttrtrs.txt, test_100_uuquqtspuu.txt, test_100_uuvvvuvvuv.txt, test_100_xxxyxxyyxx.txt, test_100_zzzyyyzyyz.txt, test_15_gunspifpdv.txt, test_17_hijkabcdab.txt, test_18_ahbicjdkea.txt, test_26_codefestiv.txt, test_33_vtootzhcdu.txt, test_72_nuauvasdgr.txt, test_73_ftnuvdtcny.txt, test_77_ksjradlaka.txt, test_77_txusqssdai.txt, test_83_amgctyikmg.txt, test_90_hseaevdcjj.txt, test_93_vpywbvvvne.txt, test_94_xliaqazebk.txt, test_98_bgefabfcgb.txt, test_98_cddabegacb.txt, test_98_cgbfcbgeed.txt, test_98_dagbdgcfbc.txt, test_98_dbcacbabad.txt, test_98_dffdbaabgf.txt, test_98_fdacgccfcd.txt, test_98_gagddgcegc.txt, test_98_gbfceggdea.txt, test_98_gddcfebeed.txt, test_a-b49.txt, test_a-b49a.txt, test_a-b50.txt, test_a-c32.txt, test_a-c32ab.txt, test_a-c33.txt, test_a-c33a.txt, test_a-pr-za-qs-z.txt, test_a-w3yyzzyyzza-w.txt, test_a-x2z46.txt, test_a-x2z47.txt, test_a-x2z52.txt, test_a-xz46a-z.txt, test_a-xz47a-z.txt, test_a-xz52a-z.txt, test_a-yy-aa-yy-a.txt, test_a-yy.txt, test_a-z.txt, test_a-z3a-u.txt, test_a-z3a-v.txt, test_a-za-z.txt, test_a-zb-za.txt, test_a-zz-a.txt, test_a3-z3.txt, test_a4-y4.txt, test_a99.txt, test_aa-y.txt, test_abababab.txt, test_abacbabc.txt, test_abcde.txt, test_az.txt, test_b100.txt, test_b4-y4dkqc.txt, test_b4-y4hhpp.txt, test_b4-z4.txt, test_byr.txt, test_kxwzajmx.txt, test_pp.txt, test_ssb4-y4ss.txt, test_x33y33z33.txt, test_x33y33z34.txt, test_x33y34z33.txt, test_x34y33z33.txt, test_z.txt, test_z98.txt
Case Name Status Exec Time Memory
test_100_bbaaababba.txt AC 25 ms 800 KB
test_100_bcbcbbccbc.txt AC 27 ms 732 KB
test_100_cccdcddccd.txt AC 26 ms 924 KB
test_100_dddccddccd.txt AC 26 ms 800 KB
test_100_kkkkjkkjkj.txt AC 26 ms 928 KB
test_100_lllklkkllk.txt AC 24 ms 932 KB
test_100_nooooonnnn.txt AC 24 ms 924 KB
test_100_prpttrstrs.txt AC 26 ms 920 KB
test_100_psupruuutq.txt AC 25 ms 920 KB
test_100_qpuutstspt.txt AC 31 ms 800 KB
test_100_qstsustsus.txt AC 27 ms 800 KB
test_100_qtrqqsqqup.txt AC 25 ms 800 KB
test_100_tpqqqrrrsp.txt AC 27 ms 800 KB
test_100_tsrrtqrqtt.txt AC 27 ms 800 KB
test_100_tussuutruq.txt AC 27 ms 808 KB
test_100_ussuttrtrs.txt AC 28 ms 808 KB
test_100_uuquqtspuu.txt AC 26 ms 804 KB
test_100_uuvvvuvvuv.txt AC 25 ms 804 KB
test_100_xxxyxxyyxx.txt AC 26 ms 796 KB
test_100_zzzyyyzyyz.txt AC 24 ms 924 KB
test_15_gunspifpdv.txt AC 25 ms 924 KB
test_17_hijkabcdab.txt AC 23 ms 928 KB
test_18_ahbicjdkea.txt AC 23 ms 932 KB
test_26_codefestiv.txt AC 25 ms 924 KB
test_33_vtootzhcdu.txt AC 25 ms 928 KB
test_72_nuauvasdgr.txt AC 25 ms 928 KB
test_73_ftnuvdtcny.txt AC 26 ms 796 KB
test_77_ksjradlaka.txt AC 26 ms 928 KB
test_77_txusqssdai.txt AC 24 ms 928 KB
test_83_amgctyikmg.txt AC 24 ms 796 KB
test_90_hseaevdcjj.txt AC 25 ms 792 KB
test_93_vpywbvvvne.txt AC 26 ms 808 KB
test_94_xliaqazebk.txt AC 27 ms 804 KB
test_98_bgefabfcgb.txt AC 25 ms 800 KB
test_98_cddabegacb.txt AC 26 ms 924 KB
test_98_cgbfcbgeed.txt AC 28 ms 800 KB
test_98_dagbdgcfbc.txt AC 27 ms 800 KB
test_98_dbcacbabad.txt AC 26 ms 796 KB
test_98_dffdbaabgf.txt AC 27 ms 796 KB
test_98_fdacgccfcd.txt AC 27 ms 800 KB
test_98_gagddgcegc.txt AC 26 ms 728 KB
test_98_gbfceggdea.txt AC 28 ms 808 KB
test_98_gddcfebeed.txt AC 26 ms 804 KB
test_a-b49.txt AC 27 ms 920 KB
test_a-b49a.txt AC 27 ms 796 KB
test_a-b50.txt AC 27 ms 804 KB
test_a-c32.txt AC 26 ms 892 KB
test_a-c32ab.txt AC 27 ms 800 KB
test_a-c33.txt AC 27 ms 796 KB
test_a-c33a.txt AC 27 ms 800 KB
test_a-pr-za-qs-z.txt AC 26 ms 928 KB
test_a-w3yyzzyyzza-w.txt AC 25 ms 800 KB
test_a-x2z46.txt AC 24 ms 808 KB
test_a-x2z47.txt AC 24 ms 796 KB
test_a-x2z52.txt AC 26 ms 808 KB
test_a-xz46a-z.txt AC 24 ms 804 KB
test_a-xz47a-z.txt AC 27 ms 808 KB
test_a-xz52a-z.txt AC 25 ms 800 KB
test_a-yy-aa-yy-a.txt AC 25 ms 804 KB
test_a-yy.txt AC 24 ms 796 KB
test_a-z.txt AC 24 ms 928 KB
test_a-z3a-u.txt AC 26 ms 932 KB
test_a-z3a-v.txt AC 27 ms 796 KB
test_a-za-z.txt AC 24 ms 928 KB
test_a-zb-za.txt AC 24 ms 812 KB
test_a-zz-a.txt AC 26 ms 920 KB
test_a3-z3.txt AC 25 ms 728 KB
test_a4-y4.txt AC 25 ms 844 KB
test_a99.txt AC 25 ms 796 KB
test_aa-y.txt AC 26 ms 796 KB
test_abababab.txt AC 23 ms 800 KB
test_abacbabc.txt AC 26 ms 800 KB
test_abcde.txt AC 25 ms 796 KB
test_az.txt AC 24 ms 800 KB
test_b100.txt AC 25 ms 800 KB
test_b4-y4dkqc.txt AC 26 ms 920 KB
test_b4-y4hhpp.txt AC 27 ms 808 KB
test_b4-z4.txt AC 27 ms 804 KB
test_byr.txt AC 23 ms 800 KB
test_kxwzajmx.txt AC 25 ms 720 KB
test_pp.txt AC 30 ms 924 KB
test_ssb4-y4ss.txt AC 27 ms 800 KB
test_x33y33z33.txt AC 32 ms 788 KB
test_x33y33z34.txt AC 25 ms 928 KB
test_x33y34z33.txt AC 26 ms 920 KB
test_x34y33z33.txt AC 26 ms 796 KB
test_z.txt AC 25 ms 728 KB
test_z98.txt AC 26 ms 920 KB