Common Boardi think test set is not full. my AC soulution uses floating arithmetic and does not work correctly on tests like 3 0 0 0 1 1 1 100000 100000 99999 right answer should be 2? What is T17 ? The same problem :( Can anybody share that testcase? Same! :) Here's a test case: 4 6 6 5 0 0 2 1 2 Which answer is correct for this test? My output (I also have WA17): 4 1 3 2 1 4 2 3 Why is it wrong? Okay, so i finally figured it out. There was a phrase «For example, if six challenges until the end “Oozma Kappa” is forty points ahead, the audience at the stadium stands will just lose interest to the game.», which made me think that to "keep in suspense", on each step, i should choose such pair, that the current total sum is as close to zero as possible. However, this approach gives WA17. The proper approach is to keep, for as long as possible, such situation that if the first team gets all 6's for the remaining participants, and second gets all 0's, the first team wins; respectively, if 2nd team gets all 6's for the remaining participants, and 1st gets all 0's, 2nd team wins. An example test: 11 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 Wrong WA17 approach gives 6 6 6 6 6 5 5 5 5 5 5 6 6 6 6 6 6 0 0 0 0 0 but last two rounds aren't interesting, because at that point 1st team has 50, and 2nd team has 36 points, and even if 2nd team gets all 6's for last two, and 1st all 0's, it's still 50:48 and 1st team wins. One of the right answers is 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 Before last two rounds, we have 48:36, and 2nd team can potentially get all 6's on last two rounds for a draw 48:48; however, after a next round we have 54:36, and only then gets clear that 2nd team isn't going to win. Cheers to Felix_Mate for a test and nice explanation. > Which answer is correct for this test? > My output (I also have WA17): > 4 1 > 3 2 > 1 4 > 2 3 > Why is it wrong? This answer is wrong. We understand that the first team is a winner after the third round: 4 1 -> 0 + (0-0) = 0 3 2 -> 0 + (5-2) = 3 1 4 -> 3 + (6-2) = 7 - we understand that the first team is a winner 2 3 -> +(6-1) = 12 Correct answer is, for example: 4 2 3 4 2 3 1 1 Explanation - we understand that the first team is a winner only after the last (forth) round: 4 2 -> 0 + (0-2) = -2 3 4 -> -2 + (5-2) = 1 2 3 -> 1 + (6-1) = 6 - we don't know who is a winner 1 1 -> 6 + (6-0) = 12 Edited by author 01.11.2018 02:24 Edited by author 01.11.2018 02:24 A nice task for implementation, but the description is quite tricky sometimes. What if Program Counter went out of last instruction? - it is ok, you can think about it as normal termination by END command Is NOP count towards overall operations count? - no, empty lines and only-label lines do not contribute to the overall number of executed commands Are labels case sensitive? - no Are operands case sensitive? - no Are variable names case sensitive? - yes What about int32 overflow? - guaranteed that there are no overflows What about % operation? - the result of A % B operation is such C that 0 <= C < B and exist some integer Q: A = Q * B + C What if 10_000_000th command is END command? - The end command terminates the program Can variable name start from digit? - no #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. 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 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? 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 #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; } 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 Thx!! Twenty times THANK YOU!!!! Edited by author 28.10.2018 18:23 Edited by author 28.10.2018 18:23 subj This might help: input: 4 4 1 2 1 4 2 3 4 3 output: 1 1 4 3 2 1 if you use dp, l, r can be (>30000). Edited by author 26.10.2018 11:42 Edited by author 26.10.2018 11:42 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 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 #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 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 :) And how to calculate the amount of combinations after I have the team distribution list? Thank you На каких значениях становить ввод? Until the end of the string. You may use: while (scanf(...) != EOF); 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). 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; } |
|