Is there a problem with Codeforces or what?

Revision en2, by -200, 2024-10-14 07:46:10

Hii! everyone,

I wrote a solution for this problem: https://codeforces.net/gym/105418/problem/B. The issue is that while my output is correct, I'm getting a verdict of "WA on testcase 1." However, there's no explanation (no jury answer provided) for why I'm getting the wrong answer.

Can you please help me identify what's going wrong?

Here's my code:

Your code here...

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ul unsigned long long 
#define int long long 

#define init ios_base::sync_with_stdio(false); cin.tie(NULL);
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define mod 1000000007
#define endd cout << "\n"
#define endl "\n"
#define came cout<<"came\n";

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; __print(x); cerr << endl;
#else 
#define debug(x)
#endif

template<class T>
void in(T a[],int n){for(int i=0;i<n;i++) cin>>a[i];}
template<class T> 
void out(T a[], int x){for(int i = 0; i < x; i++){cout << a[i] << " "; } cout << endl;}
template<class T> 
void in(vector<T>& a, int n){for(int i = 0; i < n; i++){ int x; cin >> x; a.push_back(x);}}
template<class T>
void out(vector<T> a){for(auto i : a)cout << i << " ";cout << endl;}
inline int fib(int n) {const double phi = (1 + sqrt(5)) / 2;const double psi = (1 - sqrt(5)) / 2;return round((pow(phi, n) - pow(psi, n)) / sqrt(5));}
inline int gcd(int A, int B) {if (B == 0) return A;return gcd(B, A % B);}
inline int lcm(int A, int B) {return ((A * B) / (gcd(A, B)));}

inline bool isprime(int X) {if(X==1) return 0;if (X == 2) return true;for (int i = 2; i <= sqrt(X); i++) {if ((X % i) == 0)return false;}return true;}
int Mod(string &a,int k){int rem=0;for(int i=0;i<a.size();i++){rem = (rem*10+(a[i]-'0'))%k;}return rem;}

#define MAX 2*1e5
vector<int> primes;
void sieve(){
    vector<bool>isPrime(MAX+1,true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2;i*i<=MAX;i++){
        if(isPrime[i]){
            for(int j=i*i;j<=MAX;j+=i){
                isPrime[j]=false;
            }
        }
    }
    for(int i=2;i<=MAX;i++){
        if (isPrime[i]){
            primes.push_back(i);
        }
    }
}

signed main() {
    init;
    sieve();
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);  
    #endif

    ll _ = 1;
    cin >> _;
    while(_--){
       string s;
       cin >> s;
       int n = s.size();
       vector<int> mp(26,0);
       
       for(int i=0; i<n; i++) {
           mp[s[i]-'a']++;
       }

       vector<string> o_char;

       for(int i=0; i<26; i++){
           if(mp[i] & 1){
               string tp;
               tp.push_back((char)(i+'a'));
               mp[i]--;
               o_char.push_back(tp);
           }
       }

       if(o_char.size() == 0) {
           sort(s.begin(), s.end());
           cout << "2 \n" << s << endl;
       } else {
           if(o_char.size() > 1 && (n - o_char.size()) % o_char.size() == 0) {
               int i = 0;
               while(i < 26 && mp[i] <= 0) i++;
               if(i < 26 && mp[i] > 0) {
                   for(int j = 0; i < 26; j++) {
                       while(i < 26 && mp[i] <= 0) i++;
                       if(i < 26 && mp[i] > 0) {
                           o_char[j % o_char.size()] = ((char)(i+'a') + o_char[j % o_char.size()] + (char)(i+'a'));
                           mp[i] -= 2;
                       }
                   }
               }
               cout << o_char.back().size() << endl;
               for(auto h : o_char) cout << h;
               cout << "\n";
           } else {
               cout << -1 << endl;
           }
       }
    }
}

Let me know if you spot any issues or need more information.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English -200 2024-10-14 12:22:08 426
en2 English -200 2024-10-14 07:46:10 20
en1 English -200 2024-10-14 07:39:31 3975 Initial revision (published)