Submission #1419815


Source Code Expand

import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int depth=0;
		int mindepth=0;
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='(') {
				depth++;
			}
			else {
				depth--;
			}
			if(mindepth>depth) {
				mindepth=depth;
			}
		}
		
		StringBuilder ans=new StringBuilder();
		for(int i=mindepth; i<0;i++) {
			ans.append('(');
		}
		ans.append(s);
		for (int i=0;i<depth-mindepth;i++) {
			ans.append(')');
		}
		System.out.println(ans);
	}

}

Submission Info

Submission Time
Task D - Insertion
User shinike
Language Java7 (OpenJDK 1.7.0)
Score 400
Code Size 690 Byte
Status AC
Exec Time 104 ms
Memory 20948 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 12
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
in1.txt AC 104 ms 20948 KB
in2.txt AC 95 ms 20436 KB
in3.txt AC 94 ms 18772 KB
in4.txt AC 95 ms 20820 KB
in5.txt AC 94 ms 18772 KB
in6.txt AC 95 ms 18900 KB
in7.txt AC 95 ms 20820 KB
in8.txt AC 95 ms 18772 KB
in9.txt AC 97 ms 19028 KB
s1.txt AC 96 ms 20820 KB
s2.txt AC 96 ms 20820 KB
s3.txt AC 97 ms 19028 KB