Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | Why TLE | ai123ia | 1226. йынтарбО кодяроп | 26 фев 2013 06:38 | 2 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1226 { class Program { static void Main(string[] args) {
string nach = Console.In.ReadToEnd();
char [] s = (nach +(char)0).ToCharArray();
Console.Write(NewLine(s)); // Console.Write(NewLine(NewLine(s).ToString().ToCharArray())); Console.ReadLine(); } private static StringBuilder NewLine(char[] s) { StringBuilder otvet = new StringBuilder(); bool flag = false; int firstindex = 0, sekondindex = 0; List<char> pre = new List<char>(); for (int i = 0; i < s.Length; i++) {
if (IsLetter(s[i]) && !flag) { firstindex = i; flag = true; } if (IsLetter(s[i]) && flag) { sekondindex = i; } if (flag && !IsLetter(s[i])) { pre.Clear(); for (int j = firstindex; j <= sekondindex; j++) pre.Add(s[j]); pre.Reverse();
otvet.Append(pre.ToArray()); flag = false; } if (!flag && !IsLetter(s[i])) { otvet.Append(s[i].ToString()); } } return otvet.Remove(otvet.Length-1,1); } public static bool IsLetter(char ch) { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) return true; else return false; }
} } Time limit exceeded 11 0.125 Edited by author 22.03.2012 14:13 The same as me. I also use C#, and got the same result. I don't know why we got TLE, too. I guess there must be something wrong in the system. | | WA #8 | 👨🏻💻 Spatarel Dan Constantin | 1444. Накормить элефпотама | 26 фев 2013 04:03 | 1 | WA #8 👨🏻💻 Spatarel Dan Constantin 26 фев 2013 04:03 I had some trouble passing Test #8. It turned out that if I used Epsilon = 1e-8 to compare the angles, it worked. Also, here is a tricky test, with lots of points on the same line: Input: 10 0 0 1 1 2 2 3 3 4 4 -1 -1 -2 -2 -3 -3 -4 -4 0 1 One possible solution: 10 1 2 3 4 5 10 6 7 8 9 | | Invalid limitations | Fyodor Menshikov | 1647. Раздел острова | 26 фев 2013 01:41 | 2 | My AC solution answers YES 1000.000499854463800 0.000000000000000 999.999500145786100 0.999999500145786 to test 0 0 1000 1 2000 0 Another AC program answers YES 1000.000500262685700 0.000000000000000 999.999499737564410 0.999999499737564 Absolute difference of coordinates in answers ~ 10^6, not 10^-9 as required by statement. I think current checker does not check accuracy of coordinates, but rather compare squares and perimeters of figures original triangle split to. Admins, please update limitations of the problem. Either accuracy of coordinates 10^-6 or change it to accuracy of squares and perimeters of resulting figures. And it is important what accuracy required - absolute or relative. Edited by author 27.05.2009 19:32 The answers provided here are correct. And so is the checker. | | Help pages about new compilers updated | Problemset Maintainer | | 25 фев 2013 23:12 | 3 | In the Ruby page, "More effective solution of the same problem:" is empty Thanks... This is great! I really love this site! | | A little prog that may help you during a debug | tiancaihb | 1006. Квадратные рамки | 25 фев 2013 20:31 | 2 | For all the copypaste aficionados: the sample given is .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. ...........┌─────┐................................ ...........│.....│................................ ....┌──────│.....│..........┌─┐................... ....│......│.....│..........│.│................... ....│......│.....│..........└─┘................... ....│......│....┌│────┐.............┌─┐........... ....│......└─────┘....│.............│.│........... ....│......│....│.....│.............└─┘........... ....│......│....│.....│.........┌──┐.............. ....└──────┘....│.....│.........│..│.............. ................│.....│.........│..│.............. ................└─────┘.........└──┘.............. .................................................. .................................................. | | Tests | Alexander Samal | 1221. Malevich Strikes Back! | 25 фев 2013 19:51 | 3 | Tests Alexander Samal 27 ноя 2009 11:34 8 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 8 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 0 Answers: 5 3 Re: Tests Looksery ONU 1 2/3 2 ноя 2011 02:50 5 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 1 1 Answer: 3 That's a good test indeed! Some more: 6 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 > 3 6 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > 3 6 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 > No solution 6 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 > 3 | | WA2 | alex.step | 1303. Минимальное покрытие | 25 фев 2013 04:49 | 2 | WA2 alex.step 20 июн 2012 20:27 Could anybody help me? I have WA at 2th test. Re: WA2 Erik Kvam 25 фев 2013 04:49 Hello. I also got WA on test #2, because I put a punctuation mark at the end of "No solution". Silly mistake. Best regards, Erik | | WA #8 | Vladimir | 1140. Случай на болоте | 24 фев 2013 23:44 | 2 | WA #8 Vladimir 8 дек 2012 18:35 Wrong answer 8, give me some tests, please! Написал на С++ и всё заработало. Как? Wrote in C++ and it's work! How? | | Who can give me a little hint ? | Ferhad R | 1356. Чего бы попроще | 24 фев 2013 23:29 | 2 | Who can give me a little hint ? Test 10 has T=0, take care :) | | I got Accept, but I think I have used a wrong algorithm (See the sample in this topic) | 0909100811 | 1872. Просторный офис | 24 фев 2013 20:26 | 2 | 5 1 2 3 4 5 1 3 1 3 4 5 4 5 4 5 I think the correct answer of this sample is "Let's search for another office.", but my program outputs "Ask Shiftman for help." I just couldn't squeeze my bipartite matching through the TL... Anyway, a nice test against extra greediness: 3 40 50 60 30 70 20 40 50 50 Perfect! 3 1 2 | | I always wa in test 4,please help me,thank you!!! | guojinyu | 1112. Покрытие | 24 фев 2013 18:53 | 2 | Please tell me the reason or give me the t4,thank you! This is my program: #include <cstdio> #include <iostream> #include <cstring> using namespace std; int n,result=0,xia=0,rxia; int line[110][2],era[110][2],fera[110][2]; void init() { int i,j; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d %d",&line[i][0],&line[i][1]); if(line[i][0]>line[i][1]) swap(line[i][0],line[i][1]); } for(i=1;i<n;i++) for(j=i+1;j<=n;j++) { if(line[j][0]<line[i][0]) { swap(line[i][0],line[j][0]); swap(line[i][1],line[j][1]); } if(line[j][0]==line[i][0]) if(line[j][1]<line[i][1]) { swap(line[i][0],line[j][0]); swap(line[i][1],line[j][1]); } } } void jilu(int i) { xia++; era[xia][0]=line[i][0]; era[xia][1]=line[i][1]; } void copyera() { int i; for(i=1;i<=xia;i++) { fera[i][0]=era[i][0]; fera[i][1]=era[i][1]; } } void solve() { int i,x,temp=1,now; for(x=1;x<=n;x++) { xia=0; temp=1; memset(era,0,sizeof(era)); xia++; era[xia][0]=line[x][0]; era[xia][1]=line[x][1]; now=line[x][1]; for(i=x+1;i<=n;i++) if(line[i][0]>=now) { temp++; now=line[i][1]; jilu(i); } if(temp>result) { result=temp; copyera(); rxia=xia; } } printf("%d\n",result); for(i=1;i<=rxia;i++) printf("%d %d\n",fera[i][0],fera[i][1]); } int main() { init(); solve(); return(0); } Thank you very much!!! Maybe you forget sort first just like me. | | Time limit exceeded | SCP1716RU | 1024. Перестановки | 24 фев 2013 13:35 | 1 | var a: array[1..1000, 1..10001] of integer; c, d, e: integer; label 1; begin randomize; d := 1; Readln(c); for e := 1 to c do read(a[e, 10001]) {a[e,1002]:=random(c-1)+1}; for e := 1 to c do a[e, 1] := e; 1: inc(d); //for e:= 1 to c do write (a[e,1001],' '); for e := 1 to c do a[a[e, 10001], d] := a[e, d - 1]; for e := 1 to c do if a[e, d] <> a[e, 1] then goto 1; writeln(d - 1); end. | | Someone please explain ceil() or log() function... | Urrong | 1131. Копирование | 24 фев 2013 08:29 | 5 | when i was writing my first solution i used ceil and log functions for calculating how many computers get copies with available cables (without using the same number of cables as one copy before)... so i calculated "int init = (int)ceil(log((double)k) / log(2.0));" and used that in my program but i got WA#6... then i wrote my own function that does exactly the same: int getPow(int x) { int c = 0; int n = 1; while(n < x){ c++; n *= 2; } return c; } and then i got AC... can someone explain in what case the ceil and log functions would give wrong results. THANK YOU I also didn't got that, but this is fact: I changed my ceils and logs to self-written function and got AC. It is still challenge for me to explain, why I've do the same.... Maybe the problem is due to the compiler... Same here....and I compared my log2(x)) to (int)(log((double)x) / log(2.0)) for all x from 1 to 0x7FFFFFFF on my system and they're all identical. You needn't use function log() or something else,You can use a const array like (2,4,8,16,32,64,128,256,512,1024....). | | I don't know what the wrong if,help! | csyzcyj | 1585. Пингвины | 24 фев 2013 06:56 | 1 | PLOBLEM 1: I have seen the topic "c WA why?",and I have a problem:Why the for cycle's range should be 1 to 2*n but not 1 to n?Help me,I don't know. PLOBLEM 2: my program: #include<stdio.h> #include<string.h> #include<stdlib.h> int n,max=0,count[3],a; char s[30],ans,max1; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d",&n); count[1]=0;count[2]=0;count[3]=0; for(int i=1;i<=2*n;i++) { scanf("%s",s); if(s[0]=='E') { count[1]++; if(count[1]>max) {max=count[1];max1='E';} } else if(s[0]=='L') { count[2]++; if(count[2]>max) {max=count[2];max1='L';} } else if(s[0]=='M') { count[3]++; if(count[3]>max) {max=count[3];max1='M';} } } if(max1=='E') printf("Emperor Penguin"); else if(max1=='L') printf("Little Penguin"); else if(max1=='M') printf("Macaroni Penguin"); return 0; } It can be right in my conputer(printf"Macaroni Penguin"),but it's WRONG#1 in the test. And if I change for cycle's range into 1 to n,it's WRONG,and printf"Emperor Penguin" I don't know. SO,please help me,thank you! now,this problem can pass #6 point,but W7 #include<stdio.h> #include<string.h> #include<stdlib.h> int n,max=0,count[3],a; char s[30],ans,max1,e=0,l=0,m=0; int main() { scanf("%d\n",&n); count[1]=1;count[2]=1;count[3]=1; for(int i=1;i<=2*n;i++) { scanf("%s",s); if(s[0]=='E') e++; else if(s[0]=='L') l++; else if(s[0]=='M') m++; } if(e>l&&e>m) printf("Emperor Penguin"); if(l>e&&l>m) printf("Little Penguin"); if(m>e&&m>l) printf("Macaroni Penguin");
//system("pause"); return 0; } Edited by author 24.02.2013 07:27 Edited by author 24.02.2013 07:42 | | Test #6. Whats wrong? | alexstyle | 1910. Руины титанов: сокрытый вход | 24 фев 2013 00:55 | 1 | main() { int n,i; long a[1001],maxsum=0,nsum,nmaxsum,sum=0; scanf ("%d",&n); for (i=0; i<n; i++) { scanf ("%ld",&a[i]); if (i>=2) { if (a[i-2]==a[i-1] && a[i-1]==a[i]) { sum=a[i-2]+a[i-1]+a[i]; nsum=i; }
if (sum>=maxsum) { maxsum=sum; nmaxsum=nsum; } }
} printf ("%ld %d",maxsum, nmaxsum);
} | | Accepted (sudo rm -rf) | Dan | 1787. Поворот на МЕГУ | 23 фев 2013 22:41 | 2 | //SESC USU SUDO RM -RF var a,b,c,d,i:integer; begin read(a,b); d:=0; for i:=1 to b do begin read(c); if d<0 then d:=0; d:=d-(a-c); end; if d > 0 then writeln (d) else writeln ('0'); end. Edited by author 01.12.2012 17:40 Sudo -rm -rf Rulez By Me! | | cool idea!! | ivan145 | 1049. Отважные воздухоплаватели | 23 фев 2013 19:34 | 2 | decomposed into prime factors, and then submit to the canonical form then you will get AC!!! It is a good idea! I used the same method! | | Time limit! please help | Gregory | 1131. Копирование | 23 фев 2013 18:23 | 1 | import java.util.Scanner; public class Computers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = 0; int com = in.nextInt(); int mod = in.nextInt();
if (mod == 1 && com == 1 ){ System.out.println(mod); return; }
for(int x = 1;x < com;){ if (x == 1){ x++; a++; } if (x - mod == 0 && com - x > mod){ x+=mod; a++; }else if (x - mod == 0 && com - x < mod){ x+= com - x; a++; } if (x < mod && com - x > mod){ x+=x; a++; }else if (x < mod && com - x < mod){ x+= com - x; a++; } if (x > mod && com - x > mod){ x+=mod; a++; }else if (x > mod && com - x < mod){ x+= com - x; a++; }
} System.out.println(a); } } | | It is simple problem,Do you agree? | b4die | 1280. Topological Sorting | 23 фев 2013 13:30 | 6 | No, I don't, idea is simple, but I have a problem: I get MLE of #15, and I can't fix it. I'we tried all ways of graph representation, but I always get MLE #15. Can someone please help me? Here is part of my code that uses the memory, the working part is eliminated: type TEdge=record i,j:integer end; var g:array[1..100001] of TEdge; st,deg:array[0..1001] of integer; sol:array[1..1000] of integer; n,m,i,k:integer; procedure sort(l,r:integer); var i,j:integer; k,t:TEdge; begin i:=l; j:=r; k:=g[(i+j) div 2]; while i<=j do begin while (g[i].i<k.i) or ((g[i].i=k.i) and (g[i].j<k.j)) do inc(i); while (k.i<g[j].i) or ((k.i=g[j].i) and (k.j<g[j].j)) do dec(j); if i<=j then begin t:=g[i]; g[i]:=g[j]; g[j]:=t; inc(i); dec(j) end end; if i<r then sort(i,r); if l<j then sort(l,j) end; begin assign(input,''); reset(input); readln(n,m); for i:=1 to n+1 do begin deg[i]:=0 end; for k:=1 to m do begin readln(g[k].i,g[k].j); inc(deg[g[k].j]) end; g[m+1].j:=0; g[m+1].i:=0; for i:=1 to n do read(sol[i]); sort(1,m); close(input); // working part goes here, cut because of fourth rule..... end. When i first time solution this problem o has WA and really don't understand WHY. But now i write a simple programm 20 lines and get AC. Sorry for my English. Edited by author 01.04.2005 20:05 Very simple... Edited by author 01.04.2005 20:08 Pls dont do any sort, just check for prerequisites of subjects in the left side of order for given subject. I think you should be able to get solution in O(N+M). | | Runtime error...Help please! | Gregory | 1563. Баяны | 23 фев 2013 13:29 | 2 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class ba9n { public static void array(String[] shop){ for(int x=0;x < shop.length;x++){ System.out.println(shop[x]); } }
public static void arrayscanner(String[] shop) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for(int x = 0;x < shop.length;x++){ shop[x] = in.readLine(); } }
public static void task(String[] shop){ int answer = 0; for(int x = 0,y = 0;x < shop.length;x++){ if(shop[x] == "-1"){ continue; } for(;y < shop.length;y++){
if (x == y){ continue; } if (shop[x].equals(shop[y]) == true){ answer++; shop[y] = "-1"; } } y = 0; } System.out.println(answer); }
public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in);
int allshops = in.nextInt(); String[] shop = new String[allshops];
arrayscanner(shop); //array(shop); task(shop); } } In my compiller all worked good! |
|
|