Submission #1154089
Source Code Expand
using System; using System.Text; using System.Collections.Generic; class Solve{ public Solve(){} StringBuilder sb; public static int Main(){ new Solve().Run(); return 0; } void Run(){ sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc(){ int N = int.Parse(Console.ReadLine()); string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); if(s1 == s2){ sb.Append("0\n"); } else{ List<int> stacki = new List<int>(); List<int> stacko = new List<int>(); { char c = s2[N-1]; int p = N-1; bool b = true; for(int i=N-1;i>=-1;i--){ if(i == -1 || s2[i] != c){ stacko.Add(i+1); p = Math.Min(p,i+1); while(p >= 0 && s1[p] != c){ p--; } if(p == -1){ b = false; break; } stacki.Add(p); if(i != -1){ c = s2[i]; } } } if(!b){ sb.Append("-1\n"); return; } } int max = 0; int d = 0; int spi = stacki.Count-1; int spo = stacko.Count-1; for(int i=0;i<N;i++){ if(spi >= 0 && i == stacki[spi]){ spi--; d++; } while(spo >= 0 && i == stacko[spo] + d - 1){ spo--; d--; } max = Math.Max(max,d); } sb.Append(max+1+"\n"); } } }
Submission Info
Submission Time | |
---|---|
Task | F - Shik and Copying String |
User | leign |
Language | C# (Mono 4.6.2.0) |
Score | 1500 |
Code Size | 2049 Byte |
Status | AC |
Exec Time | 78 ms |
Memory | 30176 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 21 ms | 11092 KB |
001.txt | AC | 21 ms | 11092 KB |
002.txt | AC | 21 ms | 13140 KB |
003.txt | AC | 20 ms | 9044 KB |
004.txt | AC | 21 ms | 11092 KB |
005.txt | AC | 21 ms | 11092 KB |
006.txt | AC | 21 ms | 11092 KB |
007.txt | AC | 20 ms | 11092 KB |
008.txt | AC | 21 ms | 9044 KB |
009.txt | AC | 20 ms | 11092 KB |
010.txt | AC | 21 ms | 9044 KB |
011.txt | AC | 21 ms | 9172 KB |
012.txt | AC | 21 ms | 9044 KB |
013.txt | AC | 21 ms | 9044 KB |
014.txt | AC | 22 ms | 13140 KB |
015.txt | AC | 21 ms | 11092 KB |
016.txt | AC | 21 ms | 11092 KB |
017.txt | AC | 21 ms | 9044 KB |
018.txt | AC | 21 ms | 11092 KB |
019.txt | AC | 21 ms | 9044 KB |
020.txt | AC | 21 ms | 11092 KB |
021.txt | AC | 22 ms | 11092 KB |
022.txt | AC | 21 ms | 9044 KB |
023.txt | AC | 21 ms | 11092 KB |
024.txt | AC | 22 ms | 11092 KB |
025.txt | AC | 31 ms | 16736 KB |
026.txt | AC | 62 ms | 30176 KB |
027.txt | AC | 52 ms | 24800 KB |
028.txt | AC | 78 ms | 28128 KB |
029.txt | AC | 76 ms | 29152 KB |
030.txt | AC | 48 ms | 18912 KB |
031.txt | AC | 48 ms | 20960 KB |
032.txt | AC | 48 ms | 20960 KB |
033.txt | AC | 49 ms | 18912 KB |
034.txt | AC | 48 ms | 18912 KB |
035.txt | AC | 49 ms | 20960 KB |
036.txt | AC | 48 ms | 18912 KB |
037.txt | AC | 48 ms | 18912 KB |
038.txt | AC | 48 ms | 18912 KB |
039.txt | AC | 46 ms | 17888 KB |
040.txt | AC | 64 ms | 24928 KB |
041.txt | AC | 64 ms | 27104 KB |
042.txt | AC | 61 ms | 29152 KB |
043.txt | AC | 60 ms | 27104 KB |
044.txt | AC | 60 ms | 27104 KB |
045.txt | AC | 61 ms | 29152 KB |
046.txt | AC | 60 ms | 29152 KB |
047.txt | AC | 60 ms | 27104 KB |
048.txt | AC | 61 ms | 30176 KB |
049.txt | AC | 61 ms | 30176 KB |
050.txt | AC | 49 ms | 29152 KB |
051.txt | AC | 49 ms | 30176 KB |
052.txt | AC | 42 ms | 26848 KB |
053.txt | AC | 57 ms | 24800 KB |
054.txt | AC | 57 ms | 26848 KB |
055.txt | AC | 57 ms | 24800 KB |
056.txt | AC | 57 ms | 24800 KB |
057.txt | AC | 59 ms | 24928 KB |
058.txt | AC | 57 ms | 26848 KB |
example0.txt | AC | 21 ms | 9044 KB |
example1.txt | AC | 20 ms | 9044 KB |
example2.txt | AC | 21 ms | 11092 KB |
example3.txt | AC | 20 ms | 9044 KB |