| Show all threads Hide all threads Show all messages Hide all messages |
| Why Runtime error (Stack Overflow)??? | Iqramul Islam | 1001. Reverse Root | 31 Oct 2018 17:01 | 5 |
#include <iostream> #include <math.h> using namespace std; void square() { long long int n; scanf("%lld", &n); if(n!=-1) { square(); printf("%.4f\n", sqrt(n)); } return; } int main() { square(); return 0; } http://acm.timus.ru/help.aspx?topic=cpp&locale=en Visual C++ Only. In order to increase the size of a stack and to avoid its overflow when using a “deep” recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB): #pragma comment(linker, "/STACK:16777216") sorry i don't understand .. how to set the size of the stack??? If you can explain... it might help me..... #pragma comment(linker, "/STACK:16777216") Put the line above in the very beginning of your program, that all. You shouldn't touch stack size at all. You shouldn't implement algorithms with linear depth of recursion, not more then logarithmic depth. You shouldn't place big arrays/objects on stack. Imagine you have 1-2K stack at all. You should get/implement stack data structure and solve problem using it. |
| PLZ HELP! (WA#1) | v131v [Kungur] | 1007. Code Words | 30 Oct 2018 16:07 | 1 |
My program works with tests like this: 4 0 00 0 10 11 And my program give right answers but WA#1. That my code, whats wrong?? #include <bits/stdc++.h> using namespace std; int n; string ans,q; int main() { cin >> n; while (!cin.eof()) { //while not eof reading getline(cin,q); //read 1 line ans = ""; for (int i = 0; i < q.length(); i++) //remove all except 0 and 1 if (q[i] == '0' || q[i] == '1') ans += q[i]; if (ans.length() < n-1 || ans.length() > n+1) //if its empty continue continue; int pos_sum = 0; for (int i = 0; i < ans.length(); i++) { //count sum of positions if (ans[i] == '1') { pos_sum += i+1; } } if (ans.length() > n) { //if there 1 unnecessary element check all bool fg = false; //elements and remove him for (int i = 0; i < ans.length(); i++) { int loc_pos_sum = 0; if (fg) { cout << ans[i]; continue; } for (int j = 0; j < ans.length(); j++) { if (j == i) continue; if (ans[j] == '1') loc_pos_sum += j+1 - int(j >= i); } if (loc_pos_sum % (n+1) == 0) { fg = true; } else { cout << ans[i]; } } } else if (ans.length() < n) { //if there 1 removed element bool fg = false; //check all positions for him for (int i = 0; i <= ans.length(); i++) { int loc_pos_sum = 0; if (fg) { cout << ans[i]; continue; } for (int j = 0; j < ans.length(); j++) { if (ans[j] == '1') { loc_pos_sum += j+1 + int(j >= i); } } if (loc_pos_sum % (n+1) == 0) { cout << 0; fg = true; } if ((i+1+loc_pos_sum) % (n+1) == 0) { cout << 1; fg = true; } cout << ans[i]; } } else { //if '0' replaced to '1' check all bool fg = false; //elements and replace for (int i = 0; i < ans.length(); i++) { if (ans[i] == '1' && (pos_sum-i-1)%(n+1) == 0 && !fg) { cout << 0; fg = true; } else { cout << ans[i]; } } } cout << "\n"; } return 0; } Edited by author 30.10.2018 16:07 |
| alternative answers are not accepted | ErikR | 1007. Code Words | 30 Oct 2018 15:14 | 3 |
For some inputs multiple answers are possible, e.g.: 4 1011 has two possible answers: 1111 and 1001. However only 1001 seems to be accepted. Either the wording of the problem should be changed or the alternative answers should be accepted. Sorry - I was mistaken about the rules - 1111 is not an answer for 1011. Why 1111 isn't an answer for 1011? |
| WA4 Python 3, Help pls! | Moshkov Danil | 1837. Isenbaev's Number | 30 Oct 2018 09:36 | 2 |
Somebody can give me test case 4? I don't understand why it's wrong answer... Edited by author 30.10.2018 11:59 Edited by author 01.11.2018 09:17 |
| Why Runtime error(access violation) | Iqramul Islam | 1086. Cryptography | 29 Oct 2018 23:46 | 1 |
#include <iostream> #include <math.h> using namespace std; int Prime[15000], nPrime; int mark[15000]; void sieve(int n) { int i, j, limit=sqrt(15000)+2; mark[1]=1; ///mark is not prime...so... for(i=4; i<=n; i+=2) mark[i]=1; Prime[nPrime++]=2; for(i=3; i<=n; i+=2) if(!mark[i]) { Prime[nPrime++]=i; if(i<=limit) { for(j=i*i; j<=n; j+=i*2) mark[j]=1; } } } int main() { sieve(15000); int n; cin >> n; int arr[2000]; //cout << Prime[n-1] << endl; for(int i=0; i<n; i++) { cin >> arr[i]; } for(int i=0; i<n; i++) cout << Prime[arr[i]-1] << endl; return 0; } |
| TEST#4 (attention) | Barrett | 1601. AntiCAPS | 28 Oct 2018 18:22 | 7 |
HHHHHH.KJDFDKJ(newline) ADFFG right answer
Hhhhhh.Kjdfdkj adffg I WA here for five times Edited by author 25.07.2008 08:43 Edited by author 25.07.2008 08:54 My program answers right on this, but still WA#4 Twenty times THANK YOU!!!! Edited by author 28.10.2018 18:23 Edited by author 28.10.2018 18:23 |
| Wa 3 | MSDN | 1441. From the History of Gringotts Bank | 26 Oct 2018 20:46 | 2 |
Wa 3 MSDN 21 May 2010 20:50 Re: Wa 3 👨🏻💻 Spatarel Dan Constantin 26 Oct 2018 20:46 This might help: input: 4 4 1 2 1 4 2 3 4 3 output: 1 1 4 3 2 1 |
| WA 12 | 4llower | 1203. Scientific Conference | 26 Oct 2018 13:05 | 1 |
WA 12 4llower 26 Oct 2018 13:05 if you use dp, l, r can be (>30000). |
| nvm | netufantazii | 2031. Overturned Numbers | 25 Oct 2018 21:21 | 1 |
nvm netufantazii 25 Oct 2018 21:21 Edited by author 26.10.2018 11:42 Edited by author 26.10.2018 11:42 |
| Solution spoiler. | Gilles Deleuze | 1595. Perfect Sequence | 25 Oct 2018 01:34 | 1 |
You may just want to continue the sequence from sample, for me it was enough to get it for n = 5 { 1, 3, 2, 6, 8, 4, 11, 5 } to start noticing the pattern. Alternatively, just plug it into OEIS and come across A019444 with an explanation how to compute the answer :D |
| solution: | Shen Yang | 1388. Photo | 24 Oct 2018 07:52 | 2 |
suppose the slope of line on the x>0 is k ,and slope of (0,0) to n points is k1,k2,...kn then intersection point of x1==1/(k1-k),x2=1/(k2-k)...xn=1/(kn-k) then we choose (x4-x1)/(x2-x1)==(x4'-x1')/(x2'-x1') and (x3-x2)/(x3-x4)==(x3'-x2')/(x3'-x4') we multiply these two equations guess what happens, yes: k is offset then we can get (k4-k1)*(k3-k2)/((k2-k1)*(k3-k4))==(k4'-k1')*(k3'-k2')/((k2'-k1')*(k3'-k4')) en.. this convert to string matching prolems,so suffix array can solve it Edited by author 26.10.2018 10:33 |
| Why is that wrong on the first test | dukallis | 1001. Reverse Root | 23 Oct 2018 19:02 | 2 |
#include <iostream> #include <cmath>
void rSqrt(void) { unsigned long int n = 0; if (scanf("%lu", &n) != -1) ¦ rSqrt(); else ¦ return; printf("%.4f\n", sqrt(n)); return; }
int main() { rSqrt(); return 0; } C and C++ programs are compiled on the server with the 32-bit Microsoft Visual C++ 2017 or MinGW GCC 7.1 or Clang 4.0.1. So, sizeof(unsigned long)==4. Edited by author 23.10.2018 19:03 |
| hint | Izaron | 2025. Line Fighting | 23 Oct 2018 06:32 | 2 |
hint Izaron 1 Mar 2015 18:05 You have to divide the participants into equal teams (rounded) For example, for "15 10" test - (1, 1, 1, 1, 1, 2, 2, 2, 2, 2) Good luck :) Re: hint Volodymyr Sharaienko 23 Oct 2018 06:32 And how to calculate the amount of combinations after I have the team distribution list? Thank you |
| Как решать? | Aleksandr Starkov [IATE] | 1001. Reverse Root | 22 Oct 2018 19:53 | 2 |
На каких значениях становить ввод? Until the end of the string. You may use: while (scanf(...) != EOF); |
| For C++ Users | 0blivium | 1510. Order | 19 Oct 2018 16:29 | 1 |
I got TLE for both, straightforward sort-solution (n*logn) and Moore's algorithm (n). You can avoid it using this line in your code: - ios_base::sync_with_stdio(false); Commands "cout" and "cin" are immensely slow and for large inputs, your code can get TLE. Surprisingly, both approaches differ from each other only by 0.02 sec (with the aforementioned line included). |
| WA 5 | Mohit Kumar Basak | 1498. Stroke at Full Speed | 18 Oct 2018 21:30 | 1 |
WA 5 Mohit Kumar Basak 18 Oct 2018 21:30 Here's my code- #include <bits/stdc++.h> using namespace std; bool upp,downn,leftt,rightt,avleftt,avrightt,avupp,avdownn; bool vis[105][105],vis2[105][105]; int dist[105][105]; int dist2[105][105]; int xmov[4]={0,-1,0,1}; int ymov[4]={-1,0,1,0}; int main() { // cout << "Hello World!" << endl; ios::sync_with_stdio(false); for(int i=1;i<105;i++)for(int j=1;j<105;j++)dist[i][j]=INT_MAX; int n,m,l,x1,y1,x2,y2; cin>>n>>m>>l; cin>>x1>>y1; cin>>x2>>y2;
queue <pair <int,int> > q; queue <int> distt; int ans=0; if(abs(x1-x2)+abs(y1-y2)==1){ ans=1; } vis[x1][y1]=true; dist[x1][y1]=0; vis[x2][y2]=true; q.push(make_pair(x1,y1)); distt.push(0);
while(q.empty()==0){ pair <int,int> topp=q.front(); int curdist=distt.front(); q.pop(); distt.pop(); int curx,cury,nextx,nexty; curx=topp.first; cury=topp.second; for(int i=0;i<4;i++){ nextx=curx+xmov[i]; nexty=cury+ymov[i]; if(nextx>=1&&nextx<=n&&nexty>=1&&nexty<=m){
if(vis[nextx][nexty]==false){ vis[nextx][nexty]=true; q.push(make_pair(nextx,nexty)); distt.push(curdist+1); dist[nextx][nexty]=curdist+1; } } } }
q.push(make_pair(x2,y2)); distt.push(-1); vis2[x2][y2]=true; dist2[x2][y1]=-1; while(q.empty()==0){ pair <int,int> topp=q.front(); int curdist=distt.front(); q.pop(); distt.pop(); int curx,cury,nextx,nexty; curx=topp.first; cury=topp.second; for(int i=0;i<4;i++){ nextx=curx+xmov[i]; nexty=cury+ymov[i]; if(nextx>=1&&nextx<=n&&nexty>=1&&nexty<=m){
if(vis2[nextx][nexty]==false){ vis2[nextx][nexty]=true; q.push(make_pair(nextx,nexty)); distt.push(curdist+1); dist2[nextx][nexty]=curdist+1; } } } }
for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(i==x2&&j==y2){ continue; }
if(dist[i][j]!=INT_MAX){ cout<<i<<" ::::: "<<j<<"\n"; int totaldist=dist[i][j]+dist2[i][j]; if(totaldist<=l){ ans=max(ans,max(abs(y2-j),abs(x2-i))+1); } }
} }
cout<<ans; return 0; } |
| пример | xlebuwek | 2001. Mathematicians and Berries | 17 Oct 2018 21:24 | 2 |
пример xlebuwek 17 Oct 2018 20:39 тест в примере верный? если нет можно правильный? Why do you think example is wrong? Person A has 1kg of berries in 0kg basket. Person B has 1kg of berries in 1kg basket. |
| Hint | Pastafarianist | 1005. Stone Pile | 17 Oct 2018 20:09 | 5 |
Hint Pastafarianist 19 Nov 2011 21:59 This problem can be solved using brute force. The asymptotics is O(n*2^n) but still the time limit is not hit, provided you use bit operations instead of generating arrays. For you beginners, I post my code here, but I strongly recommend to write this on your own first. The language I use is Java; nextInt() function returns the next integer from the input. [code deleted] Worst time is 0.187 sec, as reported by Timus. Edited by moderator 21.10.2019 22:59 Re: Hint Milena Araujo 22 Nov 2011 01:17 Hi ! Would you mind explaining the if on the second for ? I mean, how is this putting all different combination of blocks on each pile ? Thanks :D man u're awesome :) solution is great for that kinda bruteforce! just made all those things in cpp myself and got ACd :D but this problem's still far too hard for the "beginners" tag on which it is right now :) Can anybody translate me this code on C++ or Pascal Re: Hint Shah Habibul Imran 17 Oct 2018 20:09 Thanks, got AC converting it into C++. |
| No subject | Islam | 1423. String Tale | 17 Oct 2018 09:57 | 1 |
Please give me test 8!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| What's wrong? Guys, help!! | Sergey Volodin | 1327. Fuses | 16 Oct 2018 20:46 | 2 |
a=int(input()) b=int(input()) i=a w=0 while i<=b: w=w+1 i=i+2 if (a%10==0): w=w-1 print(w) first = int(input()) second = int(input()) count = 0 for i in range(first, second + (second % 2 != 0), 2): count += 1 print(count) |