I am getting quite unexpectedly AC in subtask 2 and WA in subtask 1.
Can someone help me find error in my code?
I have stored frequency of each element in vector c and taken cases if largest element has frequency>1 then NO or if any intermediate element has >2 then NO,and finally in all other cases YES
https://www.codechef.com/viewsolution/34822544
Hey, thank you for the explaination…
Here is my solution with a very similar approach to yours… will you please check where did i go wrong…
https://www.codechef.com/viewsolution/34825450
Also the output for your testcase is :
YES
1 3 4 9 12 13 4
The array goes on increasing until 13 and then goes strictly down.
Is this also a correct answer?
Any help would be highly appreciated.
All the cases seems to be correct and covered
But I am getting WA in Subtask 0 and AC in subtask 1
Why using more than 1 array give WA on sub- task 1 and AC on sub- task 2??
I think there is some discrepancy with using Java’s ArrayList and HashMap, couldn’t get my solution accepted with it, but the solution got accepted when applied the near same concept in Python3.
Can anyone pls tell me what is wrong with this code?? I feel that it is completely right logic wise but still I am unable to understand why do I get WA on submission.
Here is the link to my code: CodeChef: Practical coding for everyone
Same here, couldn’t pass subtask 2 because of tle
Same is the case with me.
Because after printing YES it will wait for the next input as instead of printing the sequence
Can anyone tell me what is wrong with this approach?
here is the link to my code :- CodeChef: Practical coding for everyone
I am explaining my logic here
I have taken two TreeSet and one with increasing and another decreasing and if the no. appeared first time then added it to first tree and then if occurred twice added it to second tree and if it is present in both tree then Obviosuly no will be the answer
and if last value of first tree is equal to first value of second tree (if not empty) then largest no has occured twice so answer is no… and finally printed them by joining both trees.
It is working for all the custom test case i feed
@taran_1407
My super duper easy to understand solution for this:
- Sort the sequence
- Pick all unique elements from left to right (this will be increasing).
- Pick all elements which are left in the sequence from right to left (this will be decreasing and if any element found violating this say “NO”.
Hint: I used a separated bool array to track which elements are added and which are left.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (int i = a; i < b; i++)
int main()
{
//#ifndef OJ
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
//#endif
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int arr[n];
int ans[n];
int count = 0;
loop(i, 0, n) cin >> arr[i];
sort(arr, arr + n);
int toggle = 1;
int x = 0, y = n - 1, index = -1;
//convering the array in increasing and decreasing order
loop(i, 0, n)
{
if (toggle)
ans[x++] = arr[i];
else
ans[y--] = arr[i];
toggle = toggle ^ 1;
}
loop(i, 0, n - 1)
{
if (ans[i] == ans[i + 1])
{
index = i;
break;
}
}
if (index == -1)
{
cout << "YES\n";
loop(i, 0, n) cout << ans[i] << " ";
cout << endl;
}
else
{
bool b = true;
for (int i = index; i >= 1; i--)
{
if (ans[i] <= ans[i - 1])
b = false;
}
loop(i, index + 1, n - 1)
{
if (ans[i] <= ans[i + 1])
b = false;
}
if (b == false)
{
cout << "NO\n";
}
else
{
cout << "YES\n";
loop(i, 0, n) cout << ans[i] << " ";
cout << endl;
}
}
}
}
can anyone please tell me where is my code getting wrong
Why is this code showing WA …it works fine on almost all testcases…Can someone Help out plz
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
map<int,int> p;
for(int i=0;i<n;i++){
int temp;
cin >> temp;
p[temp]++;
}
bool a = false;
for(auto it = p.begin();it != p.end();it++){
if(it->second > 2){
cout << "NO" << endl;
a = true;
break;
}
if(it-> second == 2 && (++it) == p.end() ){
cout << "NO" << endl;
a = true;
break;
}
}
if(a){
continue;
}else{
cout << "YES" << endl;
for(auto it = p.begin(); it != p.end() ;it++ ){
it->second -= 1;
cout << it->first << " ";
}
auto it = p.end();
it--;
for( ; ;it--){
if(it->second > 0){
cout << it->first << " ";
}
if(it == p.begin()){
break;
}
}
}
}
return 0;
}
This is my code, please provide testcase where my code goes wrong
https://www.codechef.com/viewsolution/34819485
I use same logic that explained above, but still got WA
You have not used endl after printing the sequence
I have two solution. One is working and other one is not . Can someone tell me the test case where it is getting rejected.
working solution = CodeChef: Practical coding for everyone
not working = CodeChef: Practical coding for everyone
Second soln is also getting tle . Somehow I solved this question in the contest. But it wasted lot of time. If someone can tell me why tle in the second solution, it would be appreciated.