Submission #953357


Source Code Expand

import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		String s = nextToken();
		String t = nextToken();
		for (int both = n; both >= 0; both--) {
			if (s.substring(n - both).equals(t.subSequence(0, both))) {
				out.println(2 * n - both);
				return;
			}
		}
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Submission Info

Submission Time
Task A - Prefix and Suffix
User mmaxio
Language Java8 (OpenJDK 1.8.0)
Score 200
Code Size 1295 Byte
Status AC
Exec Time 105 ms
Memory 8272 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 9
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt
Case Name Status Exec Time Memory
0_00.txt AC 95 ms 8144 KB
0_01.txt AC 98 ms 8144 KB
0_02.txt AC 93 ms 8272 KB
1_00.txt AC 94 ms 8148 KB
1_01.txt AC 95 ms 8144 KB
1_02.txt AC 95 ms 8148 KB
1_03.txt AC 93 ms 8144 KB
1_04.txt AC 105 ms 8148 KB
1_05.txt AC 96 ms 8268 KB