| Show all threads Hide all threads Show all messages Hide all messages |
| Guys, I accpeted but really cheated.... :-)) | Sanatbek_Matlatipov | 1915. Titan Ruins: Reconstruction of Bygones | 13 Sep 2015 21:12 | 1 |
I used Java: The following I did. 1. Declare Stack<Integer>. like this: Stack<Integer> st = new Stack<Integer>(); boolean ok = false; <--// this boolean is tricky.. :)) 2. Then, I iterate from 1 to n init i read X and i checked three given if statements in input. They are: 1.if(x>0){st.push(x);} 2.if(x==-1){pw.println(st.pop());} 3.if(x==0){ int len = st.size(); if(2*len<=n){ st.addAll((Collection) st.clone()); } else{ if(!ok){ // here If you don't use this if statement you will have Memory Limit #42... st.addAll((Collection<? extends Integer>) st.clone()); ok=true; } } } Problem is copying all stack elements... What I am really doing here is using stack clone() method. But When you do so many clones will have MemLimit. That's why I checked that my Stack size and its copies are more than N (2*len>n) then I should copy the whole stack one time not more. And I am thinking that above code worked because <b<stack size wansn't big enough when I cloned last time.... Sorry If I am mistaken and poor english. But this code AC ... |
| Thanks to authors!!! It's good problem | Felix_Mate | 1182. Team Them Up! | 13 Sep 2015 12:34 | 1 |
|
| No subject | esbybb | 1933. Guns for Battle! | 13 Sep 2015 07:07 | 2 |
Edited by author 13.09.2015 07:35 1 0 1 2 1 0 3 2 3 0 2 0 1 2 3 4 1 0 3 4 5 2 3 0 5 1 3 4 5 0 2 4 5 1 2 0 |
| wa test 3 | Shohin | 1209. 1, 10, 100, 1000... | 12 Sep 2015 14:20 | 3 |
#include <iostream> #include <math.h> using namespace std; int main() { double m,n; int a[70000],g; int N; cin>>N; for (int i=1; i<=N; i++) { cin>>m; n=(-1+sqrt(8*m+1))/2; if((n!=(int)n)){ g=n; g++; } else { g=n; } g--; int k=((1+g)*g)/2; if(m-k==1) a[i]=1; else a[i]=0; } for(int i=1;i<=N;i++) cout<<a[i]<<" "; system("pause"); return 0; } Edited by author 26.11.2013 20:50 Change your data range. try unsigned long long int, long . I had faced same problem. |
| test 5 time limit | Bohdan | 1002. Phone Numbers | 12 Sep 2015 03:22 | 1 |
222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322222222322 5 a aa afa aaaa aafaa -1 this test solved very quickly. my code: public class T1002 { public static int nnn = 100000; public static String sss = ""; public static int nnn2 = 100000; public static String sss2 = ""; public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(System.out); HashMap<String,String> hashMap = new HashMap<>(); while (true) { String s = sc.nextLine(); int length = s.length(); if (s.charAt(0) == '-' && s.charAt(1) == '1') { break; } else{ int n = sc.nextInt(); for(int i = 0;i<n;i++){ String s1 = sc.nextLine(); String s2 = change(s1); hashMap.put(s2,s1); } solve(0,length,s,hashMap,new StringBuilder("")); solve2(0,length,s,hashMap,new StringBuilder("")); if(nnn == 100000 && nnn2 == 100000){ out.println("No solution."); } else { if(nnn<nnn2){ out.println(sss); } else { out.println(sss2); } nnn = 100000; sss = ""; nnn2 = 100000; sss2 = ""; } hashMap.clear(); } } out.close(); } public static void solve(int x,int y,String s,HashMap<String,String> hashMap,StringBuilder sb){ if(x == y){ nnn = sb.length(); sss = sb.toString(); } else if(x != 0){ sb.append(" "); } for(int i = y;i>x;i--){ if(hashMap.containsKey(s.substring(x,i))){ String s1 = hashMap.get(s.substring(x,i)); if(nnn == 100000) { solve(x + s1.length(), y, s, hashMap,sb.append(s1)); } } } } public static void solve2(int x,int y,String s,HashMap<String,String> hashMap,StringBuilder sb) { if (x == y) { nnn2 = sb.length(); sss2 = sb.toString(); } else if (y != s.length()) { sb.insert(0," "); } for(int i = x;i<y;i++){ if(hashMap.containsKey(s.substring(i,y))){ String s1 = hashMap.get(s.substring(i,y)); if(nnn2 == 100000) { solve2(x, y - s1.length(), s, hashMap,sb.insert(0,s1)); } } } } public static String change(String s){ StringBuilder sb = new StringBuilder(""); for(int i = 0;i<s.length();i++){ if(s.charAt(i) == 'i' || s.charAt(i) == 'j'){ sb.append("1"); } else if(s.charAt(i) == 'g' || s.charAt(i) == 'h'){ sb.append("4"); } else if(s.charAt(i) == 'k' || s.charAt(i) == 'l'){ sb.append("5"); } else if(s.charAt(i) == 'm' || s.charAt(i) == 'n'){ sb.append("6"); } else if(s.charAt(i) == 'p' || s.charAt(i) == 'r' || s.charAt(i) == 's'){ sb.append("7"); } else if(s.charAt(i) == 'a' || s.charAt(i) == 'b' || s.charAt(i) == 'c'){ sb.append("2"); } else if(s.charAt(i) == 't' || s.charAt(i) == 'u' || s.charAt(i) == 'v'){ sb.append("8"); } else if(s.charAt(i) == 'o' || s.charAt(i) == 'q' || s.charAt(i) == 'z'){ sb.append("0"); } else if(s.charAt(i) == 'd' || s.charAt(i) == 'e' || s.charAt(i) == 'f'){ sb.append("3"); } else if(s.charAt(i) == 'w' || s.charAt(i) == 'x' || s.charAt(i) == 'y'){ sb.append("9"); } } return sb.toString(); } public static class MyScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } } |
| WA #6 Test | Filip Franik | 1654. Cipher Message | 11 Sep 2015 20:00 | 1 |
Hello, I just had a WA in test number 6. After some research found out that my code failed at this test: 1234567ikkjji890 Mind that I used numbers instead of letters for better visibility. |
| What's wrong with my code!!!!!!!!!!!!!!!! | A_human | 1079. Maximum | 11 Sep 2015 14:15 | 1 |
n=1 x=[] while(n<=10): j=int(input()) if j==0: break else: n+=1 x.append(j) def fun(k): if k==0: return 0 if k==1: return 1 if (k%2==0): return fun(k//2) if not(k%2==0): return (fun(k//2)+fun(k//2+1)) for l in range(0,len(x)): if x[l]%2==0: print(fun(x[l]-1)) if not(x[l]%2)==0: print(fun(x[l])) |
| RUNTIME ERROR #12 ??? | chanfaiwtf | 1176. Hyperchannels | 11 Sep 2015 12:47 | 1 |
i used Fleury algorithm to find a Euler cycle Edited by author 11.09.2015 12:47 |
| nail down checking order , might help | esbybb | 1823. Ideal Gas | 11 Sep 2015 07:49 | 1 |
p n p=0 and n=0 undefined p=0 and n!=0 error p!=0 and n=0 error v (p=0 error, n=0 undefined, vg<=0 error) t (n=0 error, p=0 undefined, tg<=0 error) |
| WA#3 help me! | liujian | 1651. Shortest Subchain | 10 Sep 2015 07:25 | 1 |
please help!I can't find the bug. Edited by author 10.09.2015 07:36 |
| Why WA6? | GastonFontenla | 1329. Galactic History | 9 Sep 2015 20:19 | 2 |
Why WA6? GastonFontenla 24 Aug 2015 08:42 My algorithm: I run BFS to assign levels (DISTANCE TO THE ROOT) to each node. Then, when read the queries: If the level of both nodes are the same, no exist any path between them. Answer is 0 If the level of qA is less than level of qB, maybe exist a path between them. Find it. If found a path, Answer is 1 If no path had been found, and the level of qA is greater than level of qB, Find a path. If found a path, Answer is 2 If none of the previous worked, the answer to the querie is 0. I read that it could be solved with LCA, but I think that it's better and elegant algo. Please help me. Maybe my algo is right, but my problem may be on the code. If need to see code, i'll post it. Okey, I solved it :D got AC, but the solution was rejudged. Now is TLE |
| HELP! I got WA10 | Felix_Mate | 1045. Funny Game | 9 Sep 2015 09:55 | 2 |
Edited by author 11.07.2015 20:44 I got run time error at #10 -_- |
| WA #22 | Try_to_try | 1611. Decimation | 8 Sep 2015 20:26 | 3 |
WA #22 Try_to_try 30 Oct 2011 15:59 I couldn't understand why my program got WA in test 22. Can anyone give me some help. Thanks Even i have the same problem! Can someone tell me what the mistake might be ? |
| WA14? | Xeqlol | 1787. Turn for MEGA | 8 Sep 2015 19:17 | 8 |
WA14? Xeqlol 22 Oct 2010 18:53 Re: WA14? VolkovStas[MSU_Tashkent] 26 Jun 2011 15:56 Similar problem. i have WA at the test #14. I can not understand what I have missed Who has a WA14 try to use this test: 4 4 1 5 1 5 right answer should be: 1 program mega; var n, k, p, i, s:integer; a:array[1..100] of integer; begin read(k, n); for i:=1 to n do read(a[i]); for i:=1 to n do if k<a[i] then begin p:=k-a[i]; a[i+1]:=a[i+1]+1; end; writeln(a[n+1]); end. Помогите плиз в чем ошибка! Re: WA14? {SESC USU} Zaynullin 21 Feb 2012 13:32 what do variable p? Edited by author 21.02.2012 13:33 i have that respons, but actually i didn't pass(( Тоже ошибка в 14 тесте, для этих условий: 4 4 1 5 1 5 моя программа выдает правильный результат Нашла ошибку Попробуйте такой тест: 5 3 6 5 7 Edited by author 08.09.2015 19:19 |
| WA#28 | gh0st | 1982. Electrification Plan | 8 Sep 2015 01:20 | 1 |
WA#28 gh0st 8 Sep 2015 01:20 Can anybody give some hits or information on test 28, thanks! |
| Optimal solution | Ivan Nikulin | 1136. Parliament | 6 Sep 2015 23:08 | 4 |
Is there any linear solution to this problem? I have implemented an O(NlogN) one. Let me tell you the way I've solved it. We just pick our last vertex (number) as a root and try to divide another part into 2 subtrees. In order to do this we find a border between those 2 parts, so that all numbers in the first part are less than our root and vice-versa for second part. The latter can be easily implemented using binary search. And then we just do all the same from the very beginning with both parts recursively. It's obvious that the only time-consuming part is binary search, which takes O(logN) time in the worst case. Therefore the complexity of this algorithm is O(NlogN). Here you are! I have user bst think that time is O(n) good luck! [code deleted] Edited by moderator 20.06.2020 16:13 My algorithm is not optimal.. It's like, I start from last vertex and add in BST. after I finish this, I print this tree according to problem statement. It's NlogN algorithm and I still have TLE on 9 test.. N is at most 3 000 and why isn't it enough?? :/ Because the algorithm is not optimal. If the tree is unbalanced then your solution will go to O(N ^ 2). See it yourself with a sorted input. |
| A got AC,but my algo is O(N^3). I know algo O(N*N*logN). | Felix_Mate | 1004. Sightseeing Trip | 6 Sep 2015 15:49 | 1 |
Idea is Dijkstra (N times from every node). I can proof that minimal cycle turns when we add one edge in root tree (tree of distance). Edited by author 06.09.2015 15:53 Edited by author 06.09.2015 15:54 |
| TLE on STL vector | laishao_yuan | 1934. Black Spot | 6 Sep 2015 08:19 | 1 |
|
| Go compiler is broken | Evgeny Sibil | | 5 Sep 2015 23:29 | 2 |
Every solution gives "Restricted function" Example: task "1000. A+B Problem" I'm sending the simplest ever go program (without any import or function call): package main func main() { } (solution id 6393085) And get "Restricted function an test 1": 6393085 Evgeny Sibil 1000. A+B Problem Go 1.3 Restricted function 1 |
| WA4 = the test with several possible answers | Leonid (SLenik) Andrievskiy | 1435. Financial Error | 5 Sep 2015 15:30 | 1 |
For example 3 12 23 23 67 There are three correct answers: Error in record #1. Correct number is: 21. Error in record #2. Correct number is: 32. Error in record #3. Correct number is: 32. Wrong answer for this test: Unrecoverable error. |