Общий форумFirst: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { int lenNum = int.Parse(Console.ReadLine()); for (int i = 0; i < lenNum; i++) { if (Regex.IsMatch(Console.ReadLine(), "^(?:one|out(?:put)?|in(?:put)?|puton)+$")) Console.WriteLine("YES"); else Console.WriteLine("NO"); } }} Second: using System; class Program { static void Main(string[] args) { int lenNum = int.Parse(Console.ReadLine()); for (int i = 0; i < lenNum; i++) { if (Console.ReadLine().Replace("one","").Replace("puton","").Replace("output","").Replace("input","").Replace("out","").Replace("in","")=="") Console.WriteLine("YES"); else Console.WriteLine("NO"); } }} THIRD: using System; class Program { static void Main(string[] args) { int lenNum = int.Parse(Console.ReadLine()); for (int i = 0; i < lenNum; i++) Console.WriteLine(Judge(Console.ReadLine())); } static string Judge(string input) { int pos = 0; for (int i = input.Length - 1; i >= 0; i--) { pos++; if (pos == 1||pos==4) continue; else if (pos == 2) { if (input.Substring(i, pos) == "in") pos = 0; else continue; } else if (pos == 3) { if (input.Substring(i, pos) == "one" || input.Substring(i, pos) == "out") pos = 0; else continue; } else if (pos == 5) { if (input.Substring(i, pos) == "input" || input.Substring(i, pos) == "puton") pos = 0; else continue; } else { if (input.Substring(i, pos) == "output") pos = 0; else return "NO"; } } if (pos==0) return "YES"; else return "NO"; } } All of above fail, because of "Memory limit exceeded". Edited by author 16.03.2009 07:55 The first input size is greater than 16 mb. use bytes instead of chars and strings You got ML in the reading: Console.ReadLine() This line may use up to 20 MB of memory (strings are stored in Unicode). There is a solution with O(1) memory. Try to find it. Is this problem solvable in any other way not using Segment Tree? Can this problem solved using Fenwick Tree? gcd ~ min but, we can't use fenwick tree, because, when update, new minimum should be no more than previous. but I could be wrong :) I used gcd tree and set. And I got TL 17. Then I remade my recursive update function to nonrecursive. I got AC. Then I remade my recursive get_gcd function to nonrecursive function. AND GOT TL AGAIN! Using a treap is another nice way. AC 0.296 without any optimizations (and 0.234 after some :) ) Edited by author 20.09.2011 21:38 I use SQRT-decomposition. Accept 0.468 on Java. I also solved it by Sqrt-decomposition. Accept 0.292 on C++ Could you explain a little more about "SQRT-decomposition" or where I can find an introduction to it? I tried google it but it's nowhere. Thanks! Could you explain a little more about "SQRT-decomposition" or where I can find an introduction to it? I tried google it but it's nowhere. Thanks! I used balanced bst (AVL tree), keeping GCD for each subtree. Got 0.39 Thought about segment tree but found it not so elegant. How does your segment tree solution look? ibra, Pavel Kovalenko, thanks for sqrt-decomposition hint! Edited by author 01.10.2011 21:08 Did you use some modifications to Sqrt-decomposition? I seem to be unable to AC it. I use C++ (on Java it's a bit tougher) and I use multiset for storing integer, not a vector. I get TLE 22 ... I tried to modify sizes, but that doesn't seem to help.Did you use Sqrt-decomp twice? #include<iostream> #include<string> using namespace std; int isPalindrom(string); int main(void){ string s,s1,s2; int i,j,k; cin>>s; k=0; for(i=0;i<s.size();i++) for(j=1;j<=s.size();j++) if(isPalindrom(s.substr(i,j))){ s1=s.substr(i,j); if(s1.size()>k){ k=s1.size(); s2=s1; } } cout<<s2; return 0; } int isPalindrom(string s){ int i,flag; for(i=0;i<s.size()/2;i++) if(s[i]!=s[s.size()-i-1]){ flag=0; break; } else flag=1; if(flag) return 1; else return 0; } Nevermind, solved it myself. Thanks anyway! Edited by author 19.07.2012 01:03 Edited by author 19.07.2012 01:03 I wonder how to achieve 0.001 execution time? If someone point out general approches to optimize time complexities, it'll be better! Thank you in advance! Approve. I has never got the time less than 0.015 even on this stupid problem. Maybe, the point is in the language you use? I write in C, compile as C++ code. Maybe, if I wrote in Pascal, I would approach 0.001? I believe the runtime you get also depends on the traffic of judge so if you have sent your solution for 999 times and you've got 0.015 all the time, you may send it once more, for the 1000th time and get 0.001 :-D time 0.001 is impossible the minimal time on timus is 0.014 and you should sent the problem 100 times to achieve it. It's minimal time any compilator need to read and write an so on. Hi, you can check my result it's 0.001/ id: 55151 Edited by author 28.03.2012 12:34 Edited by author 19.07.2012 00:39 KoNsyL Server 16 июл 2012 00:49 When the server will resume its work? Hello, please can some one tell me what is wrong with my program. I use DFA and read the strings from end of the string to start. But it always gets WA 1. :( import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; ////////////State Class///////////////////////////////// class State{ byte label; boolean isAccepting; ArrayList<State> childern=new ArrayList<State>(); public State(char label,boolean isAcepting){ this.label=(byte)label; this.isAccepting=isAcepting; } } ////////////////////////////////////////////////////// //////////////Main class///////////////////////////// public class Main { //Start state State start=new State('$',false);
//Current State State currentState=start;
//States in state machine State e=new State('e', false); State en=new State('n', false); State eno=new State('o', true);
State n=new State('n', false);
State ni=new State('i', true);
State no=new State('o', false); State not=new State('t', false); State notu=new State('u', false); State notup=new State('p', true);
State t=new State('t', false);
State tu=new State('u', false); State tuo=new State('o', true);
State tup=new State('p', false); State tupt=new State('t', false);
State tuptu=new State('u', false); State tuptuo=new State('o', true);
State tupn=new State('n', false); State tupni=new State('i', true);
public void constructStateTree(){
start.childern.add(e); start.childern.add(n); start.childern.add(t);
e.childern.add(en); en.childern.add(eno); eno.childern=start.childern;
n.childern.add(ni); n.childern.add(no); ni.childern=start.childern;
no.childern.add(not); not.childern.add(notu); notu.childern.add(notup); notup.childern=start.childern;
t.childern.add(tu); tu.childern.add(tuo); tu.childern.add(tup); tuo.childern=start.childern;
tup.childern.add(tupn); tup.childern.add(tupt);
tupn.childern.add(tupni); tupni.childern=start.childern;
tupt.childern.add(tuptu); tuptu.childern.add(tuptuo); tuptuo.childern=start.childern;
}
public boolean travelTree(byte c){ boolean isValid=false;
for(int i=0;i<currentState.childern.size();i++) if(c==currentState.childern.get(i).label) { currentState=currentState.childern.get(i); isValid=true; break; }
return isValid; }
public static void main(String args[]) throws IOException{ BufferedReader bfr= new BufferedReader(new InputStreamReader(System.in)); int inputSize=Integer.parseInt(bfr.readLine()); boolean isDialog=true; Main m=new Main(); m.constructStateTree(); byte[] b=new byte[10000000];
for(int i=0;i<inputSize;i++){ m.currentState=m.start; int j=0; byte sb;
while((sb= (byte) bfr.read())!=-1){ if(sb==(byte)'\n') break;
b[j]=sb; j++; }
for(j=j-1;j>=0;j--){ isDialog=m.travelTree(b[j]); if(!isDialog) break; }
if(isDialog&&m.currentState.isAccepting) System.out.println("YES"); else System.out.println("NO");
}
}
} ///////////////////////////////////////////////////// Try this test: 4 4 4 1 3 2 2 3 1 You may not still be in a comment when you finish reading all input. 1. "And you should take into account that someplace before this number in the sequence there must be a number not exceeding 35, otherwise it's not a wall, it's … well, you don't have to know what." Does it need to check? 2.Сan there be objects in the same position? Edited by author 13.07.2012 03:37 I thought that there will be presicion problems, but it turned out that ternary search works pretty well. There is a formula! It is so easy to find it using derivative! It is not so cool to solve this problem using ternary search! I tried but it was too difficult for me. Hmm, I spent about 3-5 minutes to find this formula :) #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int a; cin>>a; int b; cin>>b; int c; int tab[b]; for(int i=0; i<b; i++) { cin>>tab[i]; } for (int j=1; j<b; j++) { if (tab[j-1]-a<0) tab[j]=tab[j]; else tab[j]=tab[j]+(tab[j-1]-a);
} if (tab[b-1]-a<0) cout<<"0"<<endl; else cout<<(tab[b-1]-a)<<endl; system("PAUSE"); return EXIT_SUCCESS; } In dev-c++ it works... Edited by author 11.07.2012 19:10 Error in this line int tab[b]; Array size should be constant value. The problem is that compiler on this website(Visual C++) has a little another syntax and you can't use such thing: int b; cin>>b; int tab[b]; An array size in C++ must be initialized by a constant value, so you can't initialize it by a variable you read from the stream. Try use dynamic arrays in such cases. Edited by author 12.07.2012 13:50 I had WA5. After I spent some hours i found out that i used 100000007 instead of 1000000007, so, please, be careful. PS. If n=1000000 then answer is 71348251 I hope it will help someone someday. Just write "1000*1000*1000+7" and be happy :) $subject Edited by author 12.07.2012 01:15 Try to fix checker, please. It's possible, that some programs output more than m pairs but got AC. Why do you think so? Do you have AC program that outputs more than m pairs? Yes. Now my last submit output... about 50 pairs on test 100 3 4. But test 100 3 4 is incorrect, because there is no correct plan of the duties for it. Шёл очередной контест Петрозаводских сборов. Игроки команды Psych Up быстро нашли простую задачу, и Федя сел за компьютер. Через пять минут решение было готово. Не тратя времени на тестирование, Федя отправил его на проверку и через несколько секунд получил вердикт Time Limit Exceeded. Федя скомкал условие задачи и вышел из класса, хлопнув дверью. Что-то шло не так, нужно было развеяться. По пути в туалет он услышал разговор авторов контеста. Паша обсуждал со своим другом решение той самой задачи. Федя смог разобрать из их разговора только слова «собственные числа». Федя подумал и решил, что у него, конечно же, есть собственные числа. Например, дата рождения, номер квартиры, оценка на последнем экзамене, количество поездок на соревнования. Но ведь контест командный. А что такое собственные числа команды? Естественно, что число является собственным для команды, если оно собственное для каждого из её участников. С такими радостными мыслями Федя направился назад в аудиторию. //Он до туалета не дошел что ли?) ID=2465032 --> WA 19 ID=2465031 --> Accepted Only difference is some assertion which failed (I use assert() function from <cassert>) Why WA? Why not RE? Maybe "Release" mode disables asserts and you should use your own assert implementation to get RTE? There no checks for return value. RE only when Access Violation and some others things Code: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) {int spammers; char peeps[33][101]; bool k=true; cin>>spammers; for(int i=0; i<=spammers; i++) { peeps[31][i]=0; peeps[32][i]=0; for(int g=0; peeps[g-1][i]!='\n'; g++) { cin.get(peeps[g][i]); peeps[31][i]+=peeps[g][i]; peeps[32][i]++; } } for(int i=0; i<=spammers-1; i++) { for(int g=i+1; g<=spammers; g++) { if(peeps[31][i]==peeps[31][g] && peeps[32][i]==peeps[32][g] && peeps[31][g]!=-1) { if(k==true) { peeps[31][g]=-1; for(int y=0; peeps[y-1][g]!='\n'; y++) { cout<<peeps[y][g]; } k=false; } else { peeps[31][g]=-1; } } } k=true; } system("PAUSE"); return EXIT_SUCCESS; } Any ideas why it crashes? Sorry, your code is kind of too obfuscated for lazy me, but I would believe that you've really got access violation in your program. If you're curious, replace all arrays with vectors and use range checking access via "at". using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1788 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[] g = new int[n]; int[] b = new int[m]; input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { g[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { b[i] = int.Parse(input[i]); } int res = int.MaxValue; Array.Sort(g); Array.Sort(b); int ans = 0; if (n>=m) { for (int i = 0; i < n-m; i++) { ans += g[i]; } Console.WriteLine(ans); return; }
for (int i = 0; i <= n; i++) { ans = 0; for (int j = 0; j < m-i; j++) { ans += b[i] * i; } for (int q = 0; q < n-i; q++) { ans += g[q]; } res = Math.Min(res, ans); } Console.WriteLine(res); Console.ReadLine(); } } } Edited by author 15.05.2012 20:33 2 5 100 100 1 1 1 1 1 ans: 6 i passed this test corectly, but still have WA16 2 5 100 100 1 2 3 4 5 ans: 12
just stupid bug, if you will got AC, remove your code from forum )) Edited by author 19.05.2012 02:24 you should change >ans += b[i] * i; to >abs += b[j] * i; because when i=n you skip the cheapest elements from b[m]; Edited by author 11.07.2012 04:03 just wanted to thank the author Please give me this test. Try these tests: 1 5 3 -> 4 0 2 3 3 -> 6 2 Edited by author 09.07.2012 22:15 |
|