| Show all threads Hide all threads Show all messages Hide all messages |
| Java AC 3rd place solution | Михаил Аршинов | 1423. String Tale | 9 Aug 2015 23:39 | 1 |
//package timus; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.StringTokenizer; public class p1423 { static char[] t; static char[] p; static int[] pi; static int N; public static void main(String[] args) throws FileNotFoundException { InputStream is = System.in; FastScanner sc = new FastScanner(new InputStreamReader(is)); N = sc.nextInt(); String tt = sc.next(); tt += tt; t = tt.toCharArray(); p = sc.next().toCharArray(); pi = new int[N]; System.out.println(KMPMatcher()); } static int KMPMatcher() { computePrefixFunction(); int equals = 0; for (int i = 0; i < N + N; i++) { while (equals > 0 && p[equals] != t[i]) equals = pi[equals - 1]; if (p[equals] == t[i]) equals++; if (equals == N) { if (i == N - 1) { return 0; } else { return N + N - (i + 1); } } } return -1; } static void computePrefixFunction() { int k = 0; for (int q = 1; q < N; q++) { while (k > 0 && p[k] != p[q]) k = pi[k - 1]; if (p[k] == p[q]) k++; pi[q] = k; } } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(Reader in) { br = new BufferedReader(in); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } } |
| 2ADMINS | rip&pvs | 1798. Fire Circle. Version 2 | 9 Aug 2015 22:14 | 2 |
"floor space one million square kilometers", so maximum number of slabs damaged by the fire is 1e12, but brute force solution (TL17) with ad-don "if(res>1e12)res=1e12" has WA14 Statement is fixed, thank you. |
| Help, I have a bug in the 5 test | PEDORENKO | 1243. Divorce of the Seven Dwarfs | 9 Aug 2015 03:18 | 2 |
#include <iostream> #include <math.h> using namespace std; int main(){ double x; int i; cin >> x; x = fmod (x, 7.0); printf("%.0f",x); system("pause"); return 0; } Edited by author 18.08.2014 21:49 it's ovbious that a number of 50 digits won't fit in a double. Such number wouldn't even fit in long long. You need other method... |
| Tip for resolution | GastonFontenla | 1280. Topological Sorting | 9 Aug 2015 02:37 | 1 |
You don't need to calculate the topological order. If you first calculate the topological order, and then try to "verify" the study order, will complicate a simple problem. |
| WA 27 | Radoslav Dimitrov | 1439. Battle with You-Know-Who | 8 Aug 2015 18:36 | 1 |
WA 27 Radoslav Dimitrov 8 Aug 2015 18:36 Can anyone provide me 27th test case or tell me were am I wrong? I am using dynamic segment tree where in each node I store the count of doors in the current interval. Thanks in advance. source code: https://ideone.com/PmG5Qb Sorry for bad English |
| TLE 12 (solved) | MishaRash | 1410. Crack | 8 Aug 2015 14:46 | 1 |
I had TLE on test 12 and realized that I used only simple recursion. Once I fixed it I got AC. Edited by author 08.08.2015 14:46 |
| Help me. Why Output limit exceeded in test #1 | ThanhKa_HCMUS | 1601. AntiCAPS | 8 Aug 2015 06:23 | 1 |
Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace _1601AntiCAPS { class Program { static void Main(string[] args) { string input = Console.In.ReadToEnd(); //string input; while (input != null) { Console.Write(input[0]); for (int i = 1; i < input.Length; i++) { if (input[i] >= 'A' && input[i] <= 'Z') { int c = Convert.ToInt32(input[i]); char character = (char)(c + 32); string text = character.ToString(); Console.Write(text); } else Console.Write(input[i]); } } } } } |
| WA #17 | Eugene Butusov [KubSU] | 1297. Palindrome | 8 Aug 2015 04:36 | 4 |
WA #17 Eugene Butusov [KubSU] 27 Sep 2010 19:04 My program read string S from the input and create reverse string R from the source string. Then I search in cycle with prefix function maximum suffix which may be prefix on string S.substr(i, S.length()-i)+R i - the number of the iteration. Then I check if the getting string the palindrome, I remember then offset and length of the string. In the end print maximum substring. Got WA on 17 test. Thanks on the future...:) Re: WA #17 Лукьянчиков Владимир Игоревич 27 Sep 2010 23:31 1) First of all, you should compute prefix function on string S.substr(i, S.length()-i)+R.substr(0,S.lenght()-i); 2) add '#' between original string and reverse string: because on test "aaa" correct answer is "aaa" while your programm seems to output "aaaaa". P.S I'm not sure my advices wiil help you,so just write here your mail and i'll send you AC code - my idea is the same with yours but i don't check palindroms - prefix fuction makes by itself! Re: WA #17 Eugene Butusov [KubSU] 28 Sep 2010 00:54 Oh, I insert on concatenating between strings (original and reverse) '#' symbol and got AC! This test 'abcdesdfssaaaassss' show my Error with Manaker algorithm. |
| I don't undestend first test. Tell me explain this test, please... | Kochkin Vladimir (OSU) | 1457. Heating Main | 8 Aug 2015 01:32 | 1 |
|
| What is the test # 4? | organmusic | 1104. Don’t Ask Woman about Her Age | 8 Aug 2015 00:28 | 2 |
The test gives "wrong answer". What is the test input? |
| Am i calculating this correctly? The sample test case gives wrong answer for my calculation | TwoFace | 1104. Don’t Ask Woman about Her Age | 8 Aug 2015 00:22 | 2 |
A1A=10 1 10 For k=4, 10*(4^0)+1*(4^1)+10*(4^2)=174 174 is divisible by 3 so the answer for sample test case turns out to be 4. What am I doing wrong? Thanks |
| Some questions | Mephistos | 1177. Like Comparisons | 7 Aug 2015 20:05 | 5 |
What are answers for following comparisions? '[]' like '[]' '' like '[]' 'a' like '[--z]' 'b' like '[c-a]' '-' like '[a-f-h]' 'g' like '[a-f-h]' Thank you for your opinion... Just read the Excel, or Access rules about operator "Like", some problems will disappear. Add some success to this and you will be accepted! |
| An attempt to make the problem statement clear finally (+) | Michael_Rybak | 1177. Like Comparisons | 7 Aug 2015 20:03 | 5 |
As this problem's statement is really hard to interpret unambiguously, I've decided to make this attempt to explain my view on it, which seems to be the one that authors meant. Here’s the list of notes that make the problem more clear: in template: 1. Brackets ‘[]’ have the highest priority. Find the leftmost ‘[‘, then find the first ‘]’ after it; you can assume that these two brackets strictly correspond to each other, i.e. can’t be considered to correspond to any other brackets. Then find the first opening bracket after current closing one and so on. 2. Such templates, as [] and [^] are incorrect and don’t happen in test cases. 3. Given an opening bracket [ and a corresponding closing bracket ], let’s consider the string S between them. As Vladimir Yakovlev already stated, special characters '[', '%' and '_' mean themselves when included in brackets. Now, let’s describe a boolean function F(c,s), that determines whether template s matches character c. "Del(s,k)" will denote a function, that returns the tail of s starting from position k+1 inclusively. We shall also need a boolean function G: F: If s[1]='^', Then F(c,s):=Not G(c,Del(s,1)), Else F(c,s):=G(c,s) G: If s[2]='–' and length(s)>=3 Then G(c,s):=G(c,Del(s,3)) Or (s[1]<=c<=s[3]) Else G(c,s)=G(c,Del(s,1)) Or (s[1]=c) To my mind, these rules do make the problem statement clear and have nothing to deal with posting Source code, so I hope moderators won’t delete this message. I also want to say thank you to the person posting under nick "I have answers to all your questions :)" for helping people on this problem. In fact, your posts helped me to understand it. Thank you very much for your help. I can't imagine how much time it would take me to understand all this stuff. I think that the problem statement should be fixed. Or, should have the link to your post :) Thank you for formalized statement =) very useful! |
| 1177- Good problem | svr | 1177. Like Comparisons | 7 Aug 2015 20:01 | 3 |
The problem unexpectedly dosn't contain very tricky tests. Additionally to forum's examples I add the next: 1. Empty string corresponds with '%%%%%%%%' and so on and with empty pattern also; 2. 'a'~'%a' 3. String may contain many "like" substrings . For defining right position dublicable inner '-characters play key role; 4. Dp-method is veru useful, when we are going from ends of strings to their beginnings. Edited by author 11.07.2007 17:24 Dp-method is veru useful, when we are going from ends of strings to their beginnings. My idea is to split the template to multiple templates with no '%', and then search using some modifications of Knuth-Morris-Pratt (except for the first/last template, if there is no '%' at the beginning/end). I just don't know how fast will it be, because I have not coded it yet... DP-method is a good idea =) But I have solution without DP which works for one query as O(max(len1,len2)^2), where len1,len2 - length of string/pattern. Greedy approach only :) And in practise this method works more faster then O(max(len1,len2)^2). Look at rating of best solutions (0.001 sec VS 0.921 sec with DP). If you want I could tell you about my method. Edited by author 07.08.2015 20:01 |
| Good tests | Programmer | 1177. Like Comparisons | 7 Aug 2015 19:53 | 2 |
'ab' like '[a]b' 'ab' like '%b' 'ab' like '%%b' 'ab' like '%%%b' 'ab' like '%%%b%' 'ab' like '%%%b%%' 'b' like '%%' Edited by author 01.09.2010 00:37 :) all answers should be YES |
| ''' like ''' like ''' like ''' | glueckware | 1177. Like Comparisons | 7 Aug 2015 19:52 | 2 |
What is the right answer for the given string? Correct answer for such string is YES |
| test 11st | jaxi | 1416. Confidential | 6 Aug 2015 18:38 | 5 |
i've got a wa on test 11st,could someone give me the test data? Edited by author 26.02.2011 11:03 Edited by author 26.02.2011 11:03 I've got a wa ,too. I need test data to find question. I got wa at 10th test. Who can tell me the data? Thank you ! sunzuhan@163.com 4 6 1 2 1 1 3 5 3 4 1 4 2 3 4 1 8 2 3 0 Have a try! The right answer is 2 4 At first I forgot something and failed at #11 However, my programme shows the answer 2 4, but i failed at #11. Who can tell me why? |
| New problem 1798 "Fire Circle. Version 2" was added! | Sandro (USU) | 1798. Fire Circle. Version 2 | 6 Aug 2015 05:45 | 2 |
It is the problem 1490 "Fire Circle" with the limitation of R equal to 10^9 instead of 10^5. If you have an efficient solution of problem 1490, try to solve this one. Edited by author 02.08.2015 11:36 "Площадъю миллион квадратных километров" За пределами зала плит нет? |
| Python 2.7 help needed | Mizurnix | 1000. A+B Problem | 5 Aug 2015 18:15 | 5 |
Can not figure out the right solution that passes the test Try this solution: print sum(int(x) for x in raw_input().split(' ')) Edited by author 18.02.2013 14:11Thanks, it passed. But I am still confused; I don't get why this is a solution to the described problem (a+b) it works but i don't understand why other codes don't work Maybe your code is two line input this problem is 1 line input |
| what answer in python | krisanapat | 1000. A+B Problem | 5 Aug 2015 18:09 | 5 |
hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha a = input() b = input() print a + b it is wrong answer, why? the example code in "how to write python solutions" is functional programming style. I supposed thats what is acceptable. By the way, neither works with raw_input() and int() you should try to use raw_input().split() because the input is in the same line listname[0]+listname[1] I won't include the correct solution Edited by author 05.08.2015 18:11 Edited by author 05.08.2015 18:12 |