Submission #3605490


Source Code Expand

import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int l = in.nextInt();
		in.close();
		StringBuilder sb = new StringBuilder();
		String ls = System.lineSeparator();
		Stack<Integer> stack = new Stack<>();
		int node = 0;
		int edge = 0;
		while(l>0) {
			stack.add(l&1);
			l = l>>1;
		}
		node = stack.size();
		int num = node;
		int sum = 0;
		stack.pop();
		sum += pow2(num-1);
		while(!stack.isEmpty()) {
			num--;
			sb.append(num + " " + (num+1) + " " + 0 + ls);
			sb.append(num + " " + (num+1) + " " + pow2(num-1) + ls);
			edge += 2;
			if(stack.pop()==1) {
				sb.append(num + " " + node + " " + sum + ls);
				sum += pow2(num-1);
				edge += 1;
			}
		}
		System.out.println(node + " " + edge);
		System.out.println(sb.toString());
	}
	
	public static int pow2(int exp) {
		int ans = 1;
		for(int i=0;i<exp;i++) {
			ans *= 2;
		}
		return ans;
	}

}

Submission Info

Submission Time
Task D - All Your Paths are Different Lengths
User kiyokiyo
Language Java8 (OpenJDK 1.8.0)
Score 700
Code Size 1015 Byte
Status AC
Exec Time 104 ms
Memory 23124 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 22
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 104 ms 21076 KB
02.txt AC 93 ms 20812 KB
03.txt AC 92 ms 21716 KB
04.txt AC 93 ms 23124 KB
05.txt AC 92 ms 20692 KB
06.txt AC 92 ms 21716 KB
07.txt AC 91 ms 20052 KB
08.txt AC 93 ms 21076 KB
09.txt AC 94 ms 21716 KB
10.txt AC 93 ms 20692 KB
11.txt AC 94 ms 21204 KB
12.txt AC 93 ms 19924 KB
13.txt AC 92 ms 21716 KB
14.txt AC 94 ms 21588 KB
15.txt AC 96 ms 19796 KB
16.txt AC 93 ms 20692 KB
17.txt AC 95 ms 20176 KB
18.txt AC 94 ms 18900 KB
19.txt AC 93 ms 18512 KB
20.txt AC 93 ms 19668 KB
s1.txt AC 93 ms 20688 KB
s2.txt AC 93 ms 22608 KB