Also, the input lines are quite long. If you are using UVA's java readLine(),
set the maximum line length to a million. (I originally had it at 500 and it got WA after 0.012s, after the change it got AC after 2.1s)
And there is no need for empty line to separate the outputs, it will give u Presentation Error.
This problem is almost impossible ( well, for me at least! ) to solve it within the memory limits ( 32meg) if there were inputs of 999 x 18278 spreadsheet. But the stupid thing is that ROW*COLUMN is lot smaller than 999*18278.. yeah it seemed stupid to me because there was no indication about it in the problem statement.
So the problem now looks quiet trivial. So try to use dynamic memory.
Thanks.
But still could be tests where columns = 18278 or rows = 999, so maximum values for this two variables are necessary In problem like this you cannot deal with static tables of maximal size (it's stupid at all for such big tables) but you must use dynamic memory managment - that's all.
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Dominik Michniewski wrote:But still could be tests where columns = 18278 or rows = 999, so maximum values for this two variables are necessary
i never said that these two variables are unnecessary.
Dominik Michniewski wrote:In problem like this you cannot deal with static tables of maximal size (it's stupid at all for such big tables) but you must use dynamic memory managment - that's all.
I'm not against dynamic memory usage at all... BUT, you see, the input with 999*18278 spreadsheet is still valid according to the problem statement... and i'm afraid dynamic memory management would do a very little to solve it.
I would have liked to see something like this in the problem statement :
Assume that the product of all rows and colums is maximum XXX ( Where XXX table elements can fit in memory easily)
Just as an example of South Pacific 2k1 problem "Maximum Subsequece" http://acm.uva.es/archive/data/p2254.html
( Though the constrain specification is much necessary in p2254 than p196, but still p196 needs it i think )
greeting...
You have right in one thing: if in input exists case, in which rows and cols are maximal, this problem would be extremally hard to solve hehehe
I try to be more precision in my next posts And I didn't say that you have said that you are against something or that some variables are unnecessary
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 0.000 seconds.
And here's my code :
[cpp]#include <iostream>
#include <fstream>
#include <string>
//#include <conio.h>
#include <cmath>
#include <map>
using namespace std;
map<char,int> letters;
void allocate (string** str, int** intgrs , int r , int c)
{
str = new string*[r];
intgrs = new int*[r];
for ( int i=0 ; i<r ; i++ )
{
str = new string[c];
intgrs = new int[c];
}
}
int compute (int** rs ,const char* expr)
{
int r=0 , c=0;
int result=0;
char temp[3];
//temp[0] = expr[1]; // first letter
int size=0;
/*int i=2;*/
for ( int i=1 ; i<strlen(expr) ; )
{
while ( isalpha(expr) )
{
temp[size] = expr;
i++;
size++;
}
for (int j=0 ; j<size ; j++)
c += letters[ temp[j] ] * pow(26.0,size-j-1);
size = 0; // reset size
while ( isdigit(expr) )
{
temp[size] = expr;
i++;
size++;
}
i++; // to skip the plus sign
for (int j=0 ; j<size ; j++)
r += (temp[j]-'0') * pow(10.0,size-j-1);
result += rs[r-1][c-1];
c=r=0; // reset the c and r
}
return result;
}
void get_input (istream& in , string** spread , int r , int c)
{
for (int i=0 ; i<r ; i++)
for (int j=0 ; j<c ; j++)
in >> spread[j];
}
void set_values (string** s,int** rs, int r, int c)
{
const char* temp;
for (int i=0 ; i<r ; i++)
for (int j=0 ; j<c ; j++)
{
temp = /*static_cast<char*>*/( (s[j]).c_str() );
if ( temp[0] != '=' ) // it's a value
rs[i][j] = atoi(temp);
else // formula
rs[i][j] = compute(rs,temp);
}
}
void show_output(int** r , int rows , int columns)
{
for ( int i=0 ; i<rows ; i++ )
{
for ( int j=0 ; j<columns ; j++ )
cout << r[i][j] << ' ';
cout << endl;
}
}
int main()
{
ifstream in("in.txt");
/*map<char,int> letters;*/
char c = 'A';
int order = 1;
while ( c<='Z' )
letters[c++] = order++;
string** spread;
int** final_values;
int n;
in >> n;
for ( int i=0 ; i<n ; i++ )
{
int rows,columns;
in >> columns >> rows;
/*allocate(spread,final_values,rows,columns);*/
spread = new string*[rows];
final_values = new int*[rows];
for ( int k=0 ; k<rows ; k++ )
{
spread[k] = new string[columns];
final_values[k] = new int[columns];
}
I keep getting a presentation error on this problem, and it doesn't really describe what the format of the output should be. For those of you in a similar situation, there shouldn't be any blank lines between output cases.
max row: 999
max column: 999
formula length: 1000
formula divide into cells: 1000
formula queue size(it means how many cells are formula): 8000
cell number length: 8
it means nothing to calculate the threshold of sizes, and these sizes are enough to help you get AC.
Hope it helps.
The name of a cell consists of one to three letters for the column followed by a number between 1 and [color=#FF0000]999[/color] (including) for the row. --------- letters correspond to the number from 1 to [color=#FF0000]18278[/color].