Use cumulative count of sorted values. int64_t is not needed (e.g.WA3). Hello My solution failed on test 21. Passed next cases: 5 5 2 2 2 3 4 0 0 5 4 4 1 4 1 2 3 2 5 4 2 2 1 1 1 5 2 5 7 4 1 4 1 2 3 1 10 18 2 2 2 2 2 2 2 2 2 2 0 0 If you have any idea please let me know. Thank you Edited by author 21.08.2015 10:49 7 4 4 1 4 1 2 6 7 Ans 3 2 5 8 2 2 2 1 2 5 2 Edited by author 24.08.2019 14:48 I passed all those tests, but have WA2 :D Hi. Can anyone help me? 5 4 4 1 4 1 2 Why answer 3 2 ?? why it isn't 3 1? i can cast power = 2, then i'll destroy three coin (1, 1, 2) which is equal to 4, and i can survive. But i can't cast with power 4, because then i take (4,4) = 8 damage.
Edited by author 31.03.2018 04:18 Edited by author 31.03.2018 04:18 Edited by author 31.03.2018 04:20 >If we destroy k coins, the response will be k times stronger than our spell This means, if we destroy 3 coins (1, 1, 2) with power 2, we'll take 3*2=6 damage. test 1002 1000000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 2 answer 1002 2 Edited by author 13.02.2016 00:31 What could test 43 be? If the spell distroys 0 coins, is the minimum amount of spells also 0? Or is it 1? The amount of spells has to be 0 too. Problem #43 is the 0 0 case, but I didn't set my counters to 0 0 the right way. Not very smart. This case helped me 10 18 2 2 2 2 2 2 2 2 2 2 Thank you. This test case really helped me~ Hi! I have time limit exceeded in test 22. What's wrong with my code? What is the best approach for this task? Maybe use stack? Thanks; My code: #include <iostream> #include <vector> #include <algorithm> using namespace std; //Get all possible spell power variants vector<int> GetVariants(vector<int> vct) { vector<int> answ; for(unsigned int i=0;i<vct.size();i++) { if(find(answ.begin(),answ.end(),vct[i])==answ.end()) answ.push_back(vct[i]); } sort(answ.begin(), answ.begin()+answ.size()); reverse(answ.begin(),answ.end()); return answ; } //Get number or values, in vct which <= num (here it is destructable coins) int GetNumberOfLowerOrEqual(vector<int> vct,int num) { int number = 0; for(unsigned int i=0;i<vct.size();i++) { if(vct[i]<=num)number++; } return number; } int main() { int n,p,curr; scanf("%d",&n);//initial size of coins vector scanf("%d",&p);// health vector<int> coins; vector<int> variants; int deleted = 0; int spells = 0; for(int i=0;i<n;i++) { scanf("%d",&curr); coins.push_back(curr); } variants = GetVariants(coins); bool dChanged = false;
for(int times = 0; times<n && !coins.empty();times++) { for(int i=0;i<variants.size() && !coins.empty();i++) { if(GetNumberOfLowerOrEqual(coins,variants[i])*variants[i]<=p)//surrvived { dChanged = false; //here we remove all elements from coins, which <= variants[i] for(int t=0;t<coins.size();t++) { if(coins[t] <= variants[i]) { coins.erase(coins.begin()+t); t--; deleted++; dChanged = true; } } if(dChanged) { spells++;//if anything changed, add spell break; } } } } printf("%d ", deleted); printf("%d",spells); //system("pause"); return 0; } I have tried many tests but I didn't find what's wrong.Please give me some test!!!!! Edited by author 25.07.2014 13:04 Try this test: 5 5 2 2 2 3 4 answer: 0 0 кто-нибудь знает какой 3 ий тест ? Уже 7ой раз на нем фейлится, long'и использую. Edited by author 18.05.2014 18:13 Edited by author 18.05.2014 18:13 Sample 5 4 4 1 4 1 2 Why answer is 3 2 but not 3 1 ? 2*1+1*2 <= 4 (p = 4, p — максимальная сила всплеска, которую маги ещё могут пережить, пережить тоесть включно) ??? To kill the weakest 3 coins with one spell it would have to have spell power 2, which means you get 3*2 = 6 > 4 damage reflected. p - это суммарная сила всплеска по всем заклинаниям, которую могут выдержать волшебники, или максимальная сила всплеска за одно заклинание (каждый раз одна и та же)? ENGLISH, please Who is know test 22???? Maybe in 22 test : you can survive if [count_destroyable_coins] * [power_spell] <= [you_health]. Check your code : "<=" , not "<". Good Luck. I don't understand. So why in the test case the coins with value 4 are not killed? What am I missing? If you use spell power 4 you will destroy two coins, so the strikes back will be 2 * 4 = 8 and you can't survive The question was: is the survival limit an accumulation of all previous spells, or is it just per spell? what is it? plz // Deadly Accuracy.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <algorithm> using namespace std; int n=0,p=0; int counter[1000001]={0}; int main() { cin>>n>>p; int a=0; int maxCoins=0; int timeOfAttack=0;
for (int i=0;i<n;i++){ cin>>a; counter[a]++; }
int tempR=0; int tempCoin=0; for (int i=1;i<=p && i<=1000000;i++) { if (i*counter[i]<=p && counter[i]!=0) {
if (i*(tempCoin+counter[i])>p) { if (tempR<=p && tempCoin!=0 &&tempR !=0){ timeOfAttack++; maxCoins+=tempCoin; } tempCoin=counter[i];
} else tempCoin+=counter[i]; tempR=i*tempCoin; } } if (tempR<=p && tempCoin!=0 &&tempR !=0) { timeOfAttack++; maxCoins+=tempCoin; }
cout<<maxCoins<<' '<<timeOfAttack<<endl; cin>>a; return 0; } what is test 22? i wa 22 what's wrong? #include<stdio.h> #include<string.h> int n,p,a[1000010],min=1000000,max=0,sum=0,ans=0; int main() { int i,x,j,k; memset(a,0,sizeof(a)); scanf("%d%d",&n,&p); for(i=1; i<=n; i++) { scanf("%d",&x); a[x]++; if(x<min) min=x; if(x>max) max=x; } for(i=min; i<=max; i++) if(a[i]!=0) { if(a[i]*i>=p) break; sum+=a[i]; ans++; } for(k=min; k<i; k++) if(a[k]!=0){ for(j=k+1; j<i; j++) if(a[j]!=0) break; if(a[j]==0) break; if(j*(a[k]+a[j])<p) { ans--; a[j]+=a[k]; a[k]=0; } } printf("%d %d\n",sum,ans); return 0; } Edited by author 10.03.2013 08:41 呃…… Edited by author 10.03.2013 08:48 Edited by author 10.03.2013 08:48 you can cast a spell with power of p Incorrect: "которую могут маги ещё могут пережить" Correct: "которую маги ещё могут пережить" please!!! кто знает тест 2????? It helped me: 5 4 2 2 1 1 1 answer: 5 2 5 7 4 1 4 1 2 answer: 3 1 EDITED - NEVER mind - I think I understand Edited by author 07.11.2012 09:58 Edited by author 07.11.2012 09:58 why ans is 3 1 ? Becase 1 spell of strength 2 eliminates 3 coins (1, 1, 2) The (4,4) can never be eliminated because it causes a bounce back of 8, and 7 is the survival limit I want some tips or tests WA ON 43!!! Ouch. Input limits? Make sure variable types can hold the required range of values? solved. It's 0 0 cases thank u for attention Edited by author 19.11.2012 22:12 Edited by author 19.11.2012 22:13 Could you give me test 4? |
|