We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- All Contests
- HourRank 4
- New Year Chaos
- Discussions
New Year Chaos
New Year Chaos
Sort by
recency
|
7 Discussions
|
Please Login in order to post a comment
My appraoch is finding cycles.
1.if element is at its respective index ,we need to do nothing
2.Suppose for elements in the queue be 2 1, then one swap is
needed. accounting to 1 bribe
3.if elements in queue are 2 5 3 4 1 then 2 bribes are
needed.as 2->5->1 .
4.if that cycle increases ,then terminate .
5.Else output the total bribes count .
What is wrong with my approach . Pls explain....
code : http://ideone.com/N9E8QO
can somebody please tell me what is wrong with this code? int main(){ int t; cin >> t; while(t--) { int n,temp,bribes=0; int flag=0; cin >> n; int count_swap[n]; vector q(n); for(int q_i = 0;q_i < n;q_i++) { cin >> q[q_i];
}
TestCase 2: I/P ==>1 2 5 3 7 8 6 4 O/P ==>7
Acc to qn, a person can swap only with the person in front of him and max of 2 swaps are only allowed.
Hence, person 4 has moved to 8th position which is impossible. So, above solution should be "TOO CHAOTIC" only. How answer "7" is arrived ?
Is there anything worng in test case or is my logic wrong?
Counted the number of inversions for every element. Times out on 4 cases, how to improve it?
Hi All, I have followed the naive approach.. It takes the time n2... Here is me code... Could you suggest me how I can increase the effeciency and solve it in O(n).. I am able tos olve 60%...
include
using namespace std;
int main(){
}