Common BoardGuys, I have no idea why it doesn't pass this test. Any suggestions? public static int getMinutes(int n, int k) { if (k == 1){ return n * 2; } else if ( k >= n) { return 2; } else if (n > k) { return n - k + 2; } return 0; } BFS (Поиск в ширину). [code deleted] Edited by moderator 19.11.2019 23:14 If you decide to use SQRT-decomposition in C++ using std::set you can get TLE on test 13. All you need is to replace set -> unordered_set in your code :) (dont forget about C++11) What is Test #3? Having the same question As I had included this condition, I've past the third test: if (a == 1 || a == 2 || a == 3 || a == 7 || a == 5) Console.Write(a); Test #3 is n = 1 so you must return 1 1 second is just enough. just 0.1 sec. Because of enough time,I used dfs in 0.9sec. But I think bfs+binary will much faster... What is your algo? I used dfs and get AC with 2.1 sec. Then i use simple optimization and get Ac with 0.17 sec? It's very simple. there is a simple dp-on-subsets solution... I tried to solve it with dp-on-subsets but WA at test 7. Any hints? Also, when I use stricmp in C++, I get CE. Is this function illegal? Also, are the names unique in case-sensitive sense, or case insensitive? Does the last line in file always contain word 'Tanya'? AC with the help of "if currentTime - startTime > 3.98 then exit"~ Without this limitation, it works almost full 40 seconds on test with maxed N and M. I feel too lazy to think of effecient ways when i see such a generous time limit... try this test: 1 0 0 answer: 0 var a,b:real; begin readln(a,b); a:=a+b; write (a); end. 5 3 - 29. 100 0 - 1. 10000 10000 - http://pastebin.com/CMNizjgM . 100 100 - 1267650600228229401496703205376 Edited by author 02.03.2016 13:43 Edited by author 02.03.2016 13:44 Edited by author 23.12.2006 13:14 I also have the same problem. My algorithm runs in O(nk) time it will surely get TLE... how to optimize it? You can do it in O(n) with + and - long arithmetics Still TLE#18. I do it in O(n) with + and - long arithmetics. Help, please! Should I do long arothmetic by 4 numbers? Мне делать длинную арифметику по 4 знака? Мені робити довгу арифметику по 4 знака? :) Edited by author 23.12.2006 14:42 I got accepted, you can do long arithmetic with 8 numbers. By the way I don't think using 4 numbers (10000) as radix will TLE. :) Thanks, I have AC! But a little question: In my first solution (with 1 number) I used array[1..10000][1..3200] of shortint; than, (with 2 numbers) - array[1..10000][1..1600] of integer; Isn't it the same? But in the second case I got MLE! Whats wrong? Is sizeof(integer)=sizeof(longint)? Thanks. That depends on certain compilers. Some compilers will tend to have sizeof(shortint) = sizeof(integer) or sizeof(integer) = sizeof(longint)... that's where the problem lies...:( shortint lies in range -128..127, so sizeof(shortint)=1, while sizeof(integer)=sizeof(longint)=4. So, second array eats double amount of memory in comparison with first one. integer lies in range -32768..32767. It's 2 bytes. Ans longint is in -2147483648..2147483647 It's 4 bytes. integer lies in range -32768..32767. It's 2 bytes. Ans longint is in -2147483648..2147483647 It's 4 bytes. Do you use TP? FreePascal 32-bit compiler Integer - 32 bit Read FAQ for differences I use FP. I write a program var t:integer; begin t:=0; writeln(sizeof(t)); end. It shows 2. var t:longint; begin t:=0; writeln(sizeof(t)); end. Shows 4. sizeof(Integer) depends on version of FPC I use O(n) DP with long arithmetics on 9 digits. Because 2*a-b falls in range -1e+9 ... +2e+9 for every digit. Just use prefix sums to optimise dp. Edited by author 02.03.2016 13:39 Edited by author 03.03.2016 03:38 >I think only search is okey. >I think only search is okey. ur solution is not good. the better way is use remainder(mod) I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 Is anybody willing to tell me why it works? @Nickolas > Is anybody willing to tell me why it works? You can write a sample program and see, that permutations of 1234 produce all possible remainders in division by 7. So <some non-zero numbers><permutation on 1234><zeros> always fits. I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 No sorting, just "cutting" one : 1,2,3,4 from input number; selecting zeros and constructing "possible answer" :) cant we use dynamic programming.It is a O(2^numberofdigits) algorithm. Can any one tell me why the other solution works? 445219- No 4+4+5 = 13 2+1+9 = 12 13 and 12 = 1 Yes? Why not? "I'm one step from happiness," Vova thought, "either the previous or the next ticket is lucky." Is he right? So, you have to check if any of (445219-1) and (445219+1) is lucky. If someone is interested Test# 4 is the following Q=0; Output = 10; Ruben Alanakyan, Thank You! Thanks, man! But this test looks little bit artificial, if you know what I mean... ;) Edited by author 07.11.2008 20:08 Why the output is 10? "the minimal positive integer number Q" Q must not be greater than 0 Isn't "Q must be greater than 0" ???? thx man, It caused many failings Thank you very much! Thanks! Edited by author 26.06.2013 02:46 Doesn't make any sense but anyway, thanks a lot. Thank you so much. I leant a lot! I need to read more carefully! thank you very much !!!!!!!!!!! Спасибо! Если бы ты не сказал, я бы так и не смог сделать! Еще раз огромное спасибо! Ruben, thank you very much! lol this is "creul and unusual punishmnt" Can anybody give me the test case 1? Have you tried task example? ---- 3 6 1 2 3 2 1 1 --- Have you received the same output as in example? --- 50.00% 33.33% 16.67% --- Yes, my code gives the same output for sample test case. Here is my code- #include <iostream> #include<iomanip> using namespace std;
int main() { int n, m, vote; cin>>n>>m; int *candidates = new int[n]; for(int i=0; i<m; i++) { cin>>vote; candidates[vote-1]++; }
for(int j=0; j<n; j++) { cout<<fixed<<setprecision(2)<<float(float(candidates[j]*100)/m)<<"%"<<endl; }
return 0; } Edited by author 01.03.2016 10:07 1) What is initial value for "candidates" items? Isn't it undefined? 2) Here is my local run output: 3 6 1 1 1 2 2 3 -------- 280716864.00% 280716832.00% 280716832.00% -------- Looks like output is broken, it's visible. Have you tried to run program locally before crying in chat? Why not? 3) Why "candidates" is raw pointer? You should use vector/shared_ptr/scoped_ptr<int[]>. Or at least release array manually. Edited by author 01.03.2016 10:42 The problem was uninitialized candidates array. It worked perfectly on my local machine as the compiler I used initialized it to 0 automatically. Thanks. I am sure my solution is right. But I even can not pass the example. Hope you can help me. dp[i][0..1] means the expected time for the last i digits while the i th digit carried or not carried. f[i] means the possibility for the i th digit to carried. p[0..1][x][y] means the possibility for x, y have appeared in the last i digits while the i th digit carried or not carried. I know my code is boring and long. my code is here. #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <deque> #include <vector> #include <queue> #include <iostream> #include <algorithm> #include <map> #include <set> #include <ctime> #include <iomanip> using namespace std; typedef long long LL; typedef double DB; #define MIT (2147483647) #define INF (1000000001) #define MLL (1000000000000000001LL) #define sz(x) ((int) (x).size()) #define clr(x, y) memset(x, y, sizeof(x)) #define puf push_front #define pub push_back #define pof pop_front #define pob pop_back #define mk make_pair const int N = 5010, M = 10; int n; DB cost[M][M], p[2][M][M], tmp[2][M][M], dp[N][2], f[N]; inline void input() { scanf("%d", &n); } inline DB Cost(int x, int y, int t) { DB ptxy = p[t][x][y] + p[t][y][x]; return 1.0 * ptxy + cost[x][y] * (1 - ptxy); } inline void solve() { for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) if(i < 2 || j < 2) cost[i][j] = 1; else cost[i][j] = 2; int cnt = 0, cnt9 = 0; for(int x = 0; x < 10; x++) for(int y = 0; y < 10; y++) { if(x + y >= 10) cnt++; if(x + y == 9) cnt9++; } DB pJin = cnt / 100.0, p9 = cnt9 / 100.0; for(int i = 1; i < n; i++) f[i] = f[i - 1] * p9 + pJin; f[n] = f[n - 1] * (8 / 81.0) + (45.0 / 81.0);
int cnt00, cnt01, cnt10, cnt11; DB tmp00, tmp01, tmp10, tmp11; for(int i = 1; i < n; i++) { cnt00 = cnt01 = cnt10 = cnt11 = 0, tmp00 = tmp01 = tmp10 = tmp11 = 0; for(int x = 0; x < 10; x++) for(int y = 0; y < 10; y++) { if(x + y <= 8) { cnt00++, cnt10++; tmp00 += Cost(x, y, 0), tmp10 += Cost(x, y, 1); } else if(x + y == 9) { cnt00++, cnt11++; tmp00 += Cost(x, y, 0), tmp11 += Cost(x, y, 1); } else if(x + y >= 10) { cnt01++, cnt11++; tmp01 += Cost(x, y, 0), tmp11 += Cost(x, y, 1); } } dp[i][0] += f[i - 1] * (dp[i - 1][1] + tmp10 / cnt10 + 1) + (1 - f[i - 1]) * (dp[i - 1][0] + tmp00 / cnt00); dp[i][1] += f[i - 1] * (dp[i - 1][1] + tmp11 / cnt11 + 1) + (1 - f[i - 1]) * (dp[i - 1][0] + tmp01 / cnt01); dp[i][1] += 1; // write & mark
for(int x = 0; x < 10; x++) for(int y = 0; y < 10; y++) { if(x + y <= 8) { tmp[0][x][y] = (1 - f[i - 1]) * (p[0][x][y] + (1 - p[0][x][y]) / cnt00) + f[i - 1] * (p[1][x][y] + (1 - p[1][x][y]) / cnt10); tmp[1][x][y] = (1 - f[i - 1]) * p[0][x][y] + f[i - 1] * p[1][x][y]; } else if(x + y == 9) { tmp[0][x][y] = (1 - f[i - 1]) * (p[0][x][y] + (1 - p[0][x][y]) / cnt00) + f[i - 1] * p[1][x][y]; tmp[1][x][y] = (1 - f[i - 1]) * p[0][x][y] + f[i - 1] * (p[1][x][y] + (1 - p[1][x][y]) / cnt11); } else if(x + y >= 10) { tmp[0][x][y] = (1 - f[i - 1]) * p[0][x][y] + f[i - 1] * p[1][x][y]; tmp[1][x][y] = (1 - f[i - 1]) * (p[0][x][y] + (1 - p[0][x][y]) / cnt01) + f[i - 1] * (p[1][x][y] + (1 - p[1][x][y]) / cnt11); } } for(int t = 0; t < 2; t++) for(int x = 0; x < 10; x++) for(int y = 0; y < 10; y++) p[t][x][y] = tmp[t][x][y]; }
for(int i = 1; i < n; i++) printf("%.12lf\n", dp[i][1] * f[i] + dp[i][0] * (1 - f[i]));
cnt00 = cnt01 = cnt10 = cnt11 = 0, tmp00 = tmp01 = tmp10 = tmp11 = 0; for(int x = 1; x < 10; x++) for(int y = 1; y < 10; y++) if(x + y <= 8) { cnt00++, cnt10++; tmp00 += Cost(x, y, 0), tmp10 += Cost(x, y, 1); } else if(x + y == 9) { cnt00++, cnt11++;; tmp00 += Cost(x, y, 0), tmp11 += Cost(x, y, 1);; } else if(x + y >= 10) { cnt01++, cnt11++; tmp01 += Cost(x, y, 0), tmp11 += Cost(x, y, 1); } dp[n][0] += f[n - 1] * (dp[n - 1][1] + tmp10 / cnt10 + 1) + (1 - f[n - 1]) * (dp[n - 1][0] + tmp00 / cnt00); dp[n][1] += f[n - 1] * (dp[n - 1][1] + tmp11 / cnt11 + 1) + (1 - f[n - 1]) * (dp[n - 1][0] + tmp01 / cnt01); dp[n][1] += 1; // // write & mark & write next column
DB ans = n + f[n] * (dp[n][1] + 1) + (1 - f[n]) * dp[n][0]; printf("%.12lf\n", ans); } int main() { ios::sync_with_stdio(0); input(); solve(); return 0; } Edited by author 01.03.2016 18:27 There is task fragment: "However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches)" I thought it means that result should be int and (result*12) should be divided by 8 without reminder. I received WA3. When I ignored requirement and used simple rounding like int(result+0.5) I got ac. So, does requirement mean anything? Maybe it should be removed from task? |
|