Submission #7536877


Source Code Expand

Copy
import java.util.*;
import java.lang.*;



public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int shortEnough = 0, tooLong=N/2+1;

        while(shortEnough+1<tooLong){
            int trial = (shortEnough+tooLong)/2;
            boolean found = false;

            Map<String, Integer> dic = new HashMap<>();
            for(int l=0; l<=N-trial; l++){
                String current = S.substring(l,l+trial);
                if(dic.containsKey(current) && dic.get(current)<=l-trial){
                    found = true;
                    break;
                }else{
                    dic.putIfAbsent(current, l);
                }
            }

            if(found) shortEnough = trial;
            else tooLong = trial;
        }
        System.out.println(shortEnough);
    }
}

Submission Info

Submission Time
Task E - Who Says a Pun?
User NASU41
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 948 Byte
Status AC
Exec Time 286 ms
Memory 113992 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 70
Set Name Test Cases
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 01-handmade-08, 01-handmade-09, 01-handmade-10, 01-handmade-11, 01-handmade-12, 02-binary-13, 02-binary-14, 02-binary-15, 02-binary-16, 02-binary-17, 02-binary-18, 02-binary-19, 02-binary-20, 02-binary-21, 02-binary-22, 02-binary-23, 03-BigRandom-24, 03-BigRandom-25, 03-BigRandom-26, 03-BigRandom-27, 03-BigRandom-28, 03-BigRandom-29, 03-BigRandom-30, 03-BigRandom-31, 03-BigRandom-32, 03-BigRandom-33, 03-BigRandom-34, 03-BigRandom-35, 03-BigRandom-36, 03-BigRandom-37, 03-BigRandom-38, 03-BigRandom-39, 03-BigRandom-40, 03-BigRandom-41, 03-BigRandom-42, 03-BigRandom-43, 03-BigRandom-44, 03-BigRandom-45, 03-BigRandom-46, 03-BigRandom-47, 03-BigRandom-48, 03-BigRandom-49, 03-BigRandom-50, 03-BigRandom-51, 03-BigRandom-52, 03-BigRandom-53, 03-BigRandom-54, 04-zero-55, 04-zero-56, 05-AllRandom-57, 05-AllRandom-58, 05-AllRandom-59, 05-AllRandom-60, 05-AllRandom-61, 05-AllRandom-62, 05-AllRandom-63, 05-AllRandom-64, 05-AllRandom-65, 05-AllRandom-66, 05-AllRandom-67, 05-AllRandom-68, 05-AllRandom-69
Case Name Status Exec Time Memory
00-sample-00 AC 93 ms 18764 KB
00-sample-01 AC 98 ms 21844 KB
00-sample-02 AC 94 ms 19668 KB
01-handmade-03 AC 280 ms 61692 KB
01-handmade-04 AC 285 ms 113992 KB
01-handmade-05 AC 256 ms 92856 KB
01-handmade-06 AC 253 ms 87736 KB
01-handmade-07 AC 256 ms 92972 KB
01-handmade-08 AC 286 ms 58784 KB
01-handmade-09 AC 188 ms 46256 KB
01-handmade-10 AC 188 ms 44368 KB
01-handmade-11 AC 230 ms 64084 KB
01-handmade-12 AC 242 ms 72524 KB
02-binary-13 AC 164 ms 36436 KB
02-binary-14 AC 176 ms 36144 KB
02-binary-15 AC 161 ms 36948 KB
02-binary-16 AC 167 ms 38088 KB
02-binary-17 AC 178 ms 40316 KB
02-binary-18 AC 180 ms 39120 KB
02-binary-19 AC 150 ms 31700 KB
02-binary-20 AC 157 ms 37840 KB
02-binary-21 AC 142 ms 34132 KB
02-binary-22 AC 155 ms 34260 KB
02-binary-23 AC 153 ms 31956 KB
03-BigRandom-24 AC 231 ms 76472 KB
03-BigRandom-25 AC 248 ms 74272 KB
03-BigRandom-26 AC 231 ms 68632 KB
03-BigRandom-27 AC 246 ms 84424 KB
03-BigRandom-28 AC 253 ms 75304 KB
03-BigRandom-29 AC 249 ms 81172 KB
03-BigRandom-30 AC 246 ms 66716 KB
03-BigRandom-31 AC 237 ms 73476 KB
03-BigRandom-32 AC 259 ms 84292 KB
03-BigRandom-33 AC 237 ms 85208 KB
03-BigRandom-34 AC 240 ms 77196 KB
03-BigRandom-35 AC 215 ms 78280 KB
03-BigRandom-36 AC 234 ms 79608 KB
03-BigRandom-37 AC 237 ms 73376 KB
03-BigRandom-38 AC 239 ms 79132 KB
03-BigRandom-39 AC 241 ms 79828 KB
03-BigRandom-40 AC 235 ms 79240 KB
03-BigRandom-41 AC 255 ms 83348 KB
03-BigRandom-42 AC 256 ms 77432 KB
03-BigRandom-43 AC 246 ms 71184 KB
03-BigRandom-44 AC 223 ms 71248 KB
03-BigRandom-45 AC 253 ms 80180 KB
03-BigRandom-46 AC 235 ms 85532 KB
03-BigRandom-47 AC 257 ms 83572 KB
03-BigRandom-48 AC 232 ms 73144 KB
03-BigRandom-49 AC 222 ms 65824 KB
03-BigRandom-50 AC 261 ms 86476 KB
03-BigRandom-51 AC 249 ms 81988 KB
03-BigRandom-52 AC 247 ms 77240 KB
03-BigRandom-53 AC 247 ms 76140 KB
03-BigRandom-54 AC 250 ms 79516 KB
04-zero-55 AC 97 ms 19540 KB
04-zero-56 AC 95 ms 21844 KB
05-AllRandom-57 AC 188 ms 45136 KB
05-AllRandom-58 AC 173 ms 40104 KB
05-AllRandom-59 AC 193 ms 43204 KB
05-AllRandom-60 AC 178 ms 44372 KB
05-AllRandom-61 AC 187 ms 37056 KB
05-AllRandom-62 AC 185 ms 39160 KB
05-AllRandom-63 AC 184 ms 40352 KB
05-AllRandom-64 AC 184 ms 40352 KB
05-AllRandom-65 AC 189 ms 36400 KB
05-AllRandom-66 AC 181 ms 37056 KB
05-AllRandom-67 AC 184 ms 37156 KB
05-AllRandom-68 AC 179 ms 45056 KB
05-AllRandom-69 AC 191 ms 45268 KB