| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| To admins: weak tests | Sirko | 1130. Никифор на прогулке | 23 дек 2015 10:04 | 3 |
Edit my first comment, see the next one for complete explanation. I can share my code via email if you don't have an access to it. Edited by author 21.12.2015 22:46 My AC solution fails on following test 3 100 71 70 99 1 -71 70 It returns YES +-+ which means (71; 70) - (99; 1) + (-71; 70) = (-99; 139), |(-99; 139)|~170.65 > 141.4. But it is really strange that my AC solution contains awful mistake in sorting. In fact, sort doesn't work at all in my AC solution and output depends on vectors order! I wonder how could this code pass all tests. And I wonder how the code with fixed sorting (but still incorrect) fails on 53-th test only. Please add mentioned test. Edited by author 21.12.2015 22:48 |
| why is Wrong answer? (use Visual C++ 2013) | Huyen Pham | 1319. Отель | 22 дек 2015 10:02 | 1 |
Running in my computer is OK,use use Visual C++ 2010. But in here (use Visual C++ 2013) is wrong answer. I don't understand. Help me, please! #include <iostream> using namespace std; int main(){ int a[100][100]; int n, x=0; cout<<"\Input n: "; cin>>n; for(int j=n-1,i=0;j>=0;j--){ int h=i,k=j; while(k<n) a[h++][k++]=++x; } for(int i=1,j=0;i<n;i++){ int h=i,k=j; while(h<n) a[h++][k++]=++x; } for(int i=0; i<n ;i++){ for(int j=0; j<n ;j++){ cout.width(4); cout<<a[i][j]; } cout<<endl; } cin.ignore(80,'\n'); cin.get(); return 0; } |
| I'm trying to use stack. It's true ! Why ? | TruongNT | 1654. Шифровка | 22 дек 2015 07:45 | 1 |
import java.util.Scanner; import java.util.Stack; public class CliperMessage_1654_Stack { public static void main(String[] arg1) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); Stack<Character> stc=new Stack<>(); sb.append(sc.nextLine()); if(sb.length()<=200000){ for(int i=0;i<sb.length();i++){ if(stc.isEmpty()||(stc.peek()!=sb.charAt(i))) stc.push(sb.charAt(i)); else if((stc.peek()==sb.charAt(i))) stc.pop();
}
StringBuilder sbn=new StringBuilder(); int j=0; while(!stc.empty()) sbn.insert(j++, ""+stc.pop()); System.out.println(sbn.reverse()); } } } |
| Test case 6 ? String length =200000 ? | TruongNT | 1654. Шифровка | 22 дек 2015 07:26 | 1 |
My code using 1 while. Time limit at test case 6? public class CliperMessage_1654 { public static void main(String[] arg0) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); sb.append(sc.nextLine()); if(sb.length()<=200000){ int i=0; while(i<sb.length()-1){ if((sb.charAt(i)==sb.charAt(i+1))){ sb.deleteCharAt(i); sb.deleteCharAt(i); } else if(((i>=1)&&(sb.charAt(i-1)==sb.charAt(i)))) { sb.deleteCharAt(i-1); sb.deleteCharAt(i-1); i--; }else i++; }
System.out.println(sb); } } } |
| RUN TIME ERROR | hariharasathyanarayanan | 1101. Робот в поле | 21 дек 2015 22:09 | 2 |
Hello all :) I'm new to timus online judge.. My program work well in my system but when I submit it displays a RUN TIME ERROR i'm totally confused please help me :( :( here is my program import java.util.*; import java.io.*; import java.util.regex.*; public class RobotInTheField { public static void main(String args[]) throws IOException { String data = ""; Field field; int N,M,K; Scanner sc = new Scanner(System.in); boolean registers[] = new boolean[26]; Robot robot; Pattern p; Matcher m; BufferedReader br; ExpressionEvaluation expressionevaluation=new ExpressionEvaluation(); br=new BufferedReader(new InputStreamReader(System.in));
data = br.readLine(); // reading problem inputs
N = sc.nextInt(); M = sc.nextInt(); K = sc.nextInt();
field = new Field(N);
for(int i=0;i<M;i++) { // setting forks at the specified x and y location int x = sc.nextInt(); int y = sc.nextInt(); field.set(x,y,'f'); } //for loop ends
for(int i=0;i<K;i++) { String d = br.readLine(); /* Removing white spaces */ String split[] = d.split(" "); int x; String dummy =""; if(split[0].charAt(0) == '-'){
for(int j=1;j<split[0].length();j++) { dummy += split[0].charAt(j);
} x = Integer.parseInt(dummy); x = x*-1; } else { x = Integer.parseInt(split[0]); } dummy = ""; int y; if(split[1].charAt(0) == '-'){
for(int j=1;i<split[1].length();j++) { dummy += split[1].charAt(j);
} y = Integer.parseInt(dummy); y = x*-1; } else { y = Integer.parseInt(split[1]); }
char register = split[2].charAt(0); //System.out.println("x:"+x+",y:"+y+",ch:"+register); field.set(x,y,register); } //for loop ends
p = Pattern.compile("TRUE"); m = p.matcher(data); data = m.replaceAll("t"); p = Pattern.compile("FALSE"); m = p.matcher(data); data = m.replaceAll("f"); p = Pattern.compile("NOT"); m = p.matcher(data); data = m.replaceAll("!"); p = Pattern.compile("AND"); m = p.matcher(data); data = m.replaceAll("&"); p = Pattern.compile("OR"); m = p.matcher(data); data = m.replaceAll("|"); p = Pattern.compile(" "); m = p.matcher(data); data = m.replaceAll("");
robot=new Robot(); robot.direction="right"; while(robot.xpos >= (-1*N) && robot.xpos <= N && robot.ypos >= (-1*N) &&robot.ypos <= N) { System.out.println(robot.xpos+" "+robot.ypos);
// If robot found the fork it needs to change its direction if(field.get(robot.xpos,robot.ypos)=='f'){ // System.out.println("WARNING:ROBOT HITS THE FORK"); // robot first evaluate its expression String e = expressionevaluation.postfixConversion(data);
if(expressionevaluation.postfixevaluation(e,registers)) { if(robot.direction.equals("right")) robot.direction="down"; else if(robot.direction.equals("left")) robot.direction="up"; else if(robot.direction.equals("up")) robot.direction="right"; else if(robot.direction.equals("down")) robot.direction="left"; } else { if(robot.direction.equals("right")) robot.direction="up"; else if(robot.direction.equals("left")) robot.direction="down"; else if(robot.direction.equals("up")) robot.direction="left"; else if(robot.direction.equals("down")) robot.direction="right";
} }
else if(field.get(robot.xpos,robot.ypos) == '-') { //do nothing just move } else { char invertregister=field.get(robot.xpos,robot.ypos); if(registers[invertregister-'A']) registers[invertregister-'A']=false; else registers[invertregister-'A']=true;
}
if(robot.direction.equals("right")) robot.moveright();
else if(robot.direction.equals("left")) robot.moveleft(); else if(robot.direction.equals("up")) robot.moveup(); else if(robot.direction.equals("down")) robot.movedown();
} // System.out.println("WARNING : ROBOT ESCAPES"); // System.out.println("ROBOT POSITION "+robot.xpos+","+robot.ypos); }//main method ends here } //testexpr class ends here class ExpressionEvaluation { // Expression evaluation methods String postfixConversion(String expr) { // converting infix expression to postfix expression String postfixstring = ""; StackDataStructure stackobj=new StackDataStructure(expr.length()); boolean infinite = true;
for(int i=0;i<expr.length();i++) { // visiting each character in the string infinite = true;
switch(expr.charAt(i)) {
case '!' : stackobj.push('!'); // '!' is encountered just push them into the stack break;
case '&' : while(infinite) { // '&' is encountered just push them into the stack if(stackobj.top == 0 || stackobj.stack[stackobj.top-1] != '!') { stackobj.push('&'); infinite = false; } else postfixstring += stackobj.pop() + ""; } break;
case '(' : stackobj.push('('); // '(' is encounterd them into stack break;
case '|' : while(infinite) { // '|' is encountered if(stackobj.top == 0 || ((stackobj.stack[stackobj.top-1] != '&') && stackobj.stack[stackobj.top-1] != '!')) { stackobj.push('|'); infinite = false; } else postfixstring += stackobj.pop() + ""; } break;
case ')' : while(infinite && stackobj.top != 0) { // ')' is encountered pop elements until left parenthesis is encountered char ch=stackobj.pop();
if(ch == '(') infinite = false; else postfixstring += ch + "";
} break;
default : postfixstring += expr.charAt(i) + ""; // operands encountered }// switch case end }// for loop end
while(stackobj.top != 0) // pop remaining all elements from the stack postfixstring += stackobj.pop() + "";
return postfixstring; }// postfixexpression method ends
boolean postfixevaluation(String expr,boolean reg[]) { // postfix expression evaluation char e[] = expr.toCharArray(); // converting string into char array it makes easy to compute
for(int i=0;i<e.length;i++) { if(e[i]=='!') { // if NOT OPERATOR found for(int j=i-1;j>=0;j--) { if(e[j]=='t'||e[j]=='f') { if(e[j]=='t') e[i]='f'; else e[i]='t'; e[j]='*'; //we use that operand so we put there '*' to indicate there is no operand break; //NOT OPERATOR found its operand and operate on it so no need to search operand just breaking out } //end inner if } // end for loop } //end outer if
else if(e[i]=='&') { // if AND OPERATOR found int count = 0; // just counting operands int op[] = new int[2]; // just use to store its operands location for(int j=i-1;count<2&&j>=0;j--) { // searching two operands if two operands found the search stops if(e[j]=='t'||e[j]=='f') { //if operands are found op[count++]=j; } } if(e[op[0]]=='t'&&e[op[1]]=='t') // AND OPERATION done here e[i] = 't'; else e[i] = 'f';
e[op[0]]='*'; e[op[1]]='*'; }
else if(e[i] == '|') { // if OR OPERATOR found int count=0; int op[]=new int[2];
for(int j=i-1;count<2&&j>=0;j--) { // searching for two operands if(e[j]=='t'||e[j]=='f') { op[count++]=j; } } if(e[op[0]]=='t'||e[op[1]]=='t') // OR OPERATION done here e[i]='t'; else e[i]='f';
e[op[0]]='*'; e[op[1]]='*'; }
else { if(Character.isUpperCase(e[i])) if(reg[e[i]-'A']) { e[i]='t'; } else { e[i]='f'; } }
} // for loop ends here
if(e[e.length-1] == 't') // return boolean postfix expression evaluation return true; else return false; }//postfixevaluation method ends }//expressionevaluation class ends /* Implementing stack data structure */ class StackDataStructure { char stack[]; // stack data structure representation using arrays int top; // represent top element of the stack
StackDataStructure(int len) { // initializing stack array stack = new char[len]; }
void push(char data) { // insert element into the stack if(top == stack.length) { System.out.println("Stack overflow"); System.exit(-1); } else { stack[top++] = data; } } char pop() { // retrieving and removing stack top element from the stack if(top == 0) { System.out.println("Stack underflow"); System.exit(-1); } return stack[--top]; } void print() { // printing stack elements System.out.println("Stack elements :"); for(int i = 0; i < top; i++ ) { System.out.println(stack[i]); } } }
/* Field class represents the farm field where the robot works */ class Field { char field[][]; // representing field in two dimension int N;
Field(int n) { N = n; field = new char[N*2+1][N*2+1]; // initializing field for(int i=0;i<N*2+1;i++) { // fill empty items in the field for(int j=0;j<n*2+1;j++) { field[i][j]='-'; } } }
void print() { // printing the entire field view for(int i=0;i<N*2+1;i++) { for(int j=0;j<N*2+1;j++) { System.out.print(field[i][j]); } System.out.println(); } }
void set(int x,int y,char ch) { // set item in the field at the given x,y position field[x+N][y+N]=ch; // System.out.println("x:"+x+"y:"+y); }
char get(int x,int y) { // get item from the field by specifying x,y position return field[x+N][y+N]; }
void printdebug() { for(int i=0;i<N*2+1;i++){ for(int j=0;j<N*2+1;j++){ System.out.print(get(j-N,i-N)); } System.out.println(); } } } class Robot { int xpos = 0; int ypos = 0; String direction = "";
void moveright() { xpos++; } void moveleft() { xpos--; } void moveup() { ypos++; } void movedown() { ypos--; } } That's, uh, quite a lot of code. Almost 4x times bigger than my solution. Well, it seems to be working alright, but it's kinda hard to track down the problem.. I suggest you to comment most of the parts, then uncomment them little by little, to notice the moment when it changes from WA #1 to runtime #1, and after detecting the block which turns it into runtime, it might be easier to say what's the matter. |
| Help anybody | ELDVN | 1073. Квадратная страна | 20 дек 2015 23:22 | 1 |
Wheres my wrong? help pleas #include <bits/stdc++.h> const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; int n; int dp[maxn]={-1}; int calc(int n){ int res=n; dp[0]=0; if(dp[n] != -1) return dp[n]; for(int i=1; i*i <= n; i++){ res=min(res,1+calc(n-i*i)); } return dp[n]=res; }
int main(){ scanf("%d",&n); printf("%d\n", calc(n));
return 0; } Edited by author 20.12.2015 23:27 |
| No subject | Felix_Mate | 1176. Гиперканалы | 20 дек 2015 00:48 | 1 |
Edited by author 20.12.2015 17:14 |
| Test #15 | picture | 2010. Юный гроссмейстер Саша | 19 дек 2015 16:24 | 1 |
|
| A little question(+) | Ural_Happy New Year! | 1101. Робот в поле | 19 дек 2015 08:46 | 3 |
what means "falls out of the field". is that means the robot need to get to the [n,n]or [-n,-n]? It just means the robot goes out of the borders, i.e, x>n or x<-n or y>n or y<-n, where x and y are coordinates of the robot. Good Luck! I'm also having this question in mind thanks for the answer :) |
| TO ADMINS | † SiriuS † | 1444. Накормить элефпотама | 18 дек 2015 20:13 | 1 |
My first AC program gets WA on this test: 6 0 0 0 2 1 1 2 2 -1 -1 -2 -2 But I corrected my code :) |
| No subject | Felix_Mate | 2014. Женя переезжает от родителей | 17 дек 2015 15:45 | 1 |
Edited by author 29.12.2015 19:12 |
| I need help! | yick | 1051. Простая игра на сетке | 17 дек 2015 11:47 | 1 |
I can't understand the mean of the problem. Could you give me some help? |
| What is output for 10? | Nodir NAZAROV [TUIT-Karshi] | 2052. Физкультура | 17 дек 2015 02:24 | 3 |
There are two ways of re-forming: 1. While replacing, original line must not shift to right or left. In this case the answer is 1 (10 goes after 1, hence only 1 stays in it's place). 2. If original line can shift, then the answer is 8 (numbers from 2 to 9 doesn't move). Both algorithm failed, maybe something is missing in problem statement? What is the answer for 20? 1 or 2 or 3? |
| why runtime error (non zero exit code) in test 3!!! | Md Iqbal Hafiz | 1209. 1, 10, 100, 1000... | 16 дек 2015 16:33 | 2 |
getting runtime error in this code!! pls help me here is my code!!! #include<iostream> #include<vector> #include<algorithm> using namespace std; main() { long long int i,N,j,l; vector<long long int>k,cp; cin >> N; k.resize(N); for(i=0;i<N;i++) cin >> k[i]; cp.resize(N); cp=k; vector<int>ans; sort(cp.begin(),cp.end()); ans.resize(cp[N-1]+1); for(l=1,j=0;l<(cp[N-1]+1);l+=(++j)) ans[l]=1; for(i=0;i<N;i++) cout << ans[k[i]] << " "; return 0; } Edited by author 16.12.2015 14:03 Edited by author 16.12.2015 14:05 1) Any reason to use std::sort() instead of std::maximum_element() to find maximum element? 2) > ans.resize(cp[N-1]+1); What maximum value of "cp[N-1]+1" is? Isn't it 2^31-1? |
| МехМат МГУ очень обрадовался данной задаче. Автору уважение. | Tarek | 2067. Друзья и ягоды | 16 дек 2015 11:52 | 1 |
|
| Getting Restricted Function for Problem 1001.Reverse Root | raoviswanath | 1001. Обратный корень | 16 дек 2015 09:58 | 3 |
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.text.DecimalFormat; import java.util.Stack; public class ReverseRoot {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("Test.txt")); Stack<Double> stack = new Stack<Double>(); String str; while((str = br.readLine()) != null) { String[] tokens = str.trim().replaceAll("\\s+", " ").split(" "); for(String st : tokens) { if(!st.equals("")) stack.push(Double.parseDouble(st)); } }
br.close();
final String decimalFormatStr = "0.0000"; DecimalFormat df = new DecimalFormat(decimalFormatStr); while(stack.size() != 0) { System.out.println(df.format(Math.sqrt(stack.pop()))); }
}
} > BufferedReader br = new BufferedReader(new FileReader("Test.txt")); http://acm.timus.ru/help.aspx?topic=judgeThe program must be a console application. Input data must be read from the standard input (input from the keyboard). Output data must be printed to the standard output (screen output). Thanks a lot for pointing the issue. I will change the implementation and repost it. |
| why my modified BFS is wrong | csctcycle | 1254. Крепкий орешек | 15 дек 2015 17:39 | 1 |
I define the distance between diagonal block as sqrt(2) and others as 1. Then I use bfs to solve this problem but wa in #4 I don't know the reason.please help |
| Mistake in description | Semyon Grendel' | 1237. Evacuation Plan | 14 дек 2015 13:02 | 1 |
I suppose there is a mistake in the word 'there'. I believe, it must be 'three' "Each line contains there integer numbers Xi, Yi, and Bi" |
| No subject | Bahodir | TUIT of IT | | 2031. Числа-перевёртыши | 14 дек 2015 12:56 | 6 |
No subject Bahodir | TUIT of IT | 23 янв 2015 23:49 Edited by author 27.01.2015 16:39 import java.util.Scanner; /** * Created by Coder on 23.01.2015. */ public class OverturnedNumbers2031_ { public static void main(String[] args) { Scanner x = new Scanner(System.in); int n = x.nextInt(); if (n == 1) { System.out.println("01"); } else if (n == 2) { System.out.println("11 01"); } else if (n == 4) { System.out.println("16 06 68 88"); } else { System.out.println("Glupenky Pierre"); } } } You did not write a case of n=3.. Thanks a lot of.I got it. n = 3 -> "16 06 68"; Edited by author 14.02.2015 22:43 The best solution ever xD Why only 4 cases ?? Not all these are ok ?? "11", "01", "08", "06", "09", "10", "18", "16", "19", "80", "81", "86", "88", "89", "60", "68", "61", "66", "69", "90", "91", "98", "96", "99" |
| WA#14 and have no idea | zmj159 | 1256. Кладбищенский сторож | 14 дек 2015 08:33 | 1 |
I think I have considered all possible special situations, but don't know any other tricks. And I think it must be a trick about precision. |