ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 8):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <set>

#include <stack>

#include <queue>

#include <unordered_map>

#include <unordered_set>

#define io                            \

ios_base::sync_with_stdio(false); \

cin.tie(NULL);                    \

cout.tie(NULL);

#define endl "\n"

typedef long long ll;

#define yes cout << "YES" << endl

#define no cout << "NO" << endl

using namespace std;

bool check(string &s, int start)

{

int n = s.size();



bool change = false;

for (int i = n - 1; i > start; i--)

{

int prev = s[i - 1] - '0';

int curr = s[i] - '0';



if (prev < curr - 1)

{

change = true;

s[i - 1] = (curr - 1) + '0';

s[i] = prev + '0';

}

}



return change;

}

void solve()

{

string s;

cin >> s;



int end = s.size() - 1;

int start = 0;

while (check(s, start))

{

// end--;

start++;

// cout << s << endl;

}



cout << s << endl;

}

signed main()

{

io int t = 1;

cin >> t;

while (t--)

{

solve();

}

return 0;

}

Submission (verdict: Time limit exceeded on test 6):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <set>

#include <stack>

#include <queue>

#include <unordered_map>

#include <unordered_set>

#define io                            \

ios_base::sync_with_stdio(false); \

cin.tie(NULL);                    \

cout.tie(NULL);

#define endl "\n"

typedef long long ll;

#define yes cout << "YES" << endl

#define no cout << "NO" << endl

using namespace std;

bool check(string &s, int start)

{

int n = s.size();



bool change = false;

for (int i = n - 1; i > start; i--)

{

int prev = s[i - 1] - '0';

int curr = s[i] - '0';



if (prev < curr - 1)

{

change = true;

s[i - 1] = (curr - 1) + '0';

s[i] = prev + '0';

}

}



return change;

}

void solve()

{

string s;

cin >> s;



int n = s.size();



bool change = false;

for (int i = n - 1; i > 0; i--)

{

int prev = s[i - 1] - '0';

int curr = s[i] - '0';



if (prev < curr - 1)

{

s[i - 1] = (curr - 1) + '0';

s[i] = prev + '0';



i = n;

}

}



cout << s << endl;

}

signed main()

{

io int t = 1;

cin >> t;

while (t--)

{

solve();

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=n-1;j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i] <<endl;
    	}
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=n-1;j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i];
    	}
    	cout<<endl;
    }
    return 0;
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=min(n-1, i+12);j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i];
    	}
    	cout<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=n-1;j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i] <<endl;
    	}
    }
    return 0;
}



Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define ll long long int



int main(){
    int t;					cin>>t;
    while(t--){
    	string s;
    	cin>>s;
    	int n=s.size();
    	vector<int>a;
    	for(int i=0;i<n;i++){
    		a.push_back(s[i]-'0');
    	}

    	for(int i=0;i<n;i++){
            int indx=i;
            int mx= a[i];
            for(int j=i;j<=n-1;j++){
                if(a[j]-(j-i)>=0 and a[j]-(j-i)>mx){
                    mx= a[j]-(j-i);
                    indx=j;
                }
            }
            while(indx>i){
                a[indx]--;
                swap(a[indx],a[indx-1]);
                indx--;
            }
    	}
    	for(int i=0;i<n;i++){
            cout<< a[i];
    	}
    	cout<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<int> a(n);
        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if(freqMap.find(a[i]) != freqMap.end()){
                freqMap[a[i]]++;
            } else{
                freqMap[a[i]] = 1;
            }
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; (i < frequencies.size()) && (k > 0); i++) {
            if (frequencies[i] > 0 && k >= frequencies[i]) {
                k -= frequencies[i];
                distinctCount--;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            freqMap[x]++;
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; i < frequencies.size() && k > 0; i++) {
            if (k >= frequencies[i]) {
                k -= frequencies[i];
                distinctCount--;
            } else {
                break;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<int> a(n);
        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            if(freqMap.find(a[i]) != freqMap.end()){
                freqMap[a[i]]++;
            } else{
                freqMap[a[i]] = 1;
            }
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; i < frequencies.size() && k > 0; ++i) {
            if (frequencies[i] > 0) {
                k -= frequencies[i];
                distinctCount--;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<int> a(n);
        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            if(freqMap.find(a[i]) != freqMap.end()){
                freqMap[a[i]]++;
            } else{
                freqMap[a[i]] = 1;
            }
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; i < frequencies.size() && k > 0; ++i) {
            if (frequencies[i] > 0) {
                k -= frequencies[i];
                distinctCount--;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<int> a(n);
        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if(freqMap.find(a[i]) != freqMap.end()){
                freqMap[a[i]]++;
            } else{
                freqMap[a[i]] = 1;
            }
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; (i < frequencies.size()) && (k > 0); i++) {
            if (frequencies[i] > 0 && k >= frequencies[i]) {
                k -= frequencies[i];
                distinctCount--;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
using namespace std;

int main() {

    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        unordered_map<int, int> freqMap;

        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            freqMap[x]++;
        }

        // Count distinct elements in the array
        int distinctCount = freqMap.size();

        // Collect frequencies in a vector and sort in descending order
        vector<int> frequencies;
        for (const auto& entry : freqMap) {
            frequencies.push_back(entry.second);
        }
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        for (int i = 0; i < frequencies.size() && k > 0; i++) {
            if (k >= frequencies[i]) {
                k -= frequencies[i];
                distinctCount--;
            } else {
                break;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t; // Number of test cases
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        vector<int> a(n);

        // Input the array
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        // Sort the array to group identical elements
        sort(a.begin(), a.end());

        // Count frequencies
        vector<int> frequencies;
        int count = 1; // Start with the first element

        for (int i = 1; i < n; i++) {
            if (a[i] == a[i - 1]) {
                count++;
            } else {
                frequencies.push_back(count);
                count = 1; // Reset count for the next element
            }
        }
        // Push the last frequency
        frequencies.push_back(count);

        // Sort frequencies in ascending order
        sort(frequencies.begin(), frequencies.end());

        // Minimize distinct elements
        int distinctCount = frequencies.size();

        for (int i = 0; i < frequencies.size() && k > 0; i++) {
            if (k >= frequencies[i]) {
                k -= frequencies[i];
                distinctCount--;
            } else {
                break;
            }
        }

        // Output the result for this test case
        cout << max(1, distinctCount) << '\n';
    }

    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 

//#include <atcoder/all>

using namespace std;

//using namespace atcoder;

//using mint = modint998244353;

//long long型=int64_tという認識で大丈夫です。

#define ll long long

#define ull unsigned long long

#define vec vector

#define vi vector<int>

#define vll vector<ll>

#define pq priority_queue

#define pb push_back

#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++)

#define ld long double



const ll INF = 1e9;

const ll inf = 9e18;



struct Edge {

    int to;

    ll cost;

};



struct SEdge {

    int to;

    pair<ll, ll> cost;

};



template<class T>

using spq = priority_queue<T, vec<T>, greater<T>>; 



const vector<int> di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1};



template<class T>

bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



template<class T>

bool chmax(T& a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}



using S = ll;



S op(S a, S b) {return a + b;}

S e() {return 0;}



int main() {

    int t; cin >> t;

    rep(i, 0, t) {

        int n, x, y; cin >> n >> x >> y; x--; y--;

        vi ans(n, 0);

        rep(j, 0, n) {

            ans[j] = j % 2;

        }

        if(n % 2 == 1) ans[n - 1] = 2;

        if(ans[x] == ans[y]) ans[max(x, y)] = 2;

        rep(j, 0, n) cout << ans[j] << " ";

        cout << endl;

    }

}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h> 

//#include <atcoder/all>

using namespace std;

//using namespace atcoder;

//using mint = modint998244353;

//long long型=int64_tという認識で大丈夫です。

#define ll long long

#define ull unsigned long long

#define vec vector

#define vi vector<int>

#define vll vector<ll>

#define pq priority_queue

#define pb push_back

#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++)

#define ld long double



const ll INF = 1e9;

const ll inf = 9e18;



struct Edge {

    int to;

    ll cost;

};



struct SEdge {

    int to;

    pair<ll, ll> cost;

};



template<class T>

using spq = priority_queue<T, vec<T>, greater<T>>; 



const vector<int> di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1};



template<class T>

bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



template<class T>

bool chmax(T& a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}



using S = ll;



S op(S a, S b) {return a + b;}

S e() {return 0;}



int main() {

    int t; cin >> t;

    rep(i, 0, t) {

        int n, x, y; cin >> n >> x >> y; x--; y--;

        vi ans(n, 0);

        rep(j, 0, n) {

            ans[j] = j % 2;

        }

        if(n % 2 == 1) ans[n - 1] = 2;

        if(ans[x] == ans[y]) ans[max(x, y)] = 2;

        if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;}

        rep(j, 0, n) cout << ans[j] << " ";

        cout << endl;

    }

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h> 

//#include <atcoder/all>

using namespace std;

//using namespace atcoder;

//using mint = modint998244353;

//long long型=int64_tという認識で大丈夫です。

#define ll long long

#define ull unsigned long long

#define vec vector

#define vi vector<int>

#define vll vector<ll>

#define pq priority_queue

#define pb push_back

#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++)

#define ld long double



const ll INF = 1e9;

const ll inf = 9e18;



struct Edge {

    int to;

    ll cost;

};



struct SEdge {

    int to;

    pair<ll, ll> cost;

};



template<class T>

using spq = priority_queue<T, vec<T>, greater<T>>; 



const vector<int> di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1};



template<class T>

bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



template<class T>

bool chmax(T& a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}



using S = ll;



S op(S a, S b) {return a + b;}

S e() {return 0;}



int main() {

    int t; cin >> t;

    rep(i, 0, t) {

        int n, x, y; cin >> n >> x >> y; x--; y--;

        vi ans(n, 0);

        rep(j, 0, n) {

            ans[j] = j % 2;

        }

        if(n % 2 == 1) ans[n - 1] = 2;

        if(ans[x] == ans[y]) ans[max(x, y)] = 2;

        rep(j, 0, n) cout << ans[j] << " ";

        cout << endl;

    }

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h> 

//#include <atcoder/all>

using namespace std;

//using namespace atcoder;

//using mint = modint998244353;

//long long型=int64_tという認識で大丈夫です。

#define ll long long

#define ull unsigned long long

#define vec vector

#define vi vector<int>

#define vll vector<ll>

#define pq priority_queue

#define pb push_back

#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++)

#define ld long double



const ll INF = 1e9;

const ll inf = 9e18;



struct Edge {

    int to;

    ll cost;

};



struct SEdge {

    int to;

    pair<ll, ll> cost;

};



template<class T>

using spq = priority_queue<T, vec<T>, greater<T>>; 



const vector<int> di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1};



template<class T>

bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



template<class T>

bool chmax(T& a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}



using S = ll;



S op(S a, S b) {return a + b;}

S e() {return 0;}



int main() {

    int t; cin >> t;

    rep(i, 0, t) {

        int n, x, y; cin >> n >> x >> y; x--; y--;

        vi ans(n, 0);

        rep(j, 0, n) {

            ans[j] = j % 2;

        }

        if(n % 2 == 1) ans[n - 1] = 2;

        if(ans[x] == ans[y]) ans[max(x, y)] = 2;

        if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;}

        rep(j, 0, n) cout << ans[j] << " ";

        cout << endl;

    }

}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h> 

//#include <atcoder/all>

using namespace std;

//using namespace atcoder;

//using mint = modint998244353;

//long long型=int64_tという認識で大丈夫です。

#define ll long long

#define ull unsigned long long

#define vec vector

#define vi vector<int>

#define vll vector<ll>

#define pq priority_queue

#define pb push_back

#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++)

#define ld long double



const ll INF = 1e9;

const ll inf = 9e18;



struct Edge {

    int to;

    ll cost;

};



struct SEdge {

    int to;

    pair<ll, ll> cost;

};



template<class T>

using spq = priority_queue<T, vec<T>, greater<T>>; 



const vector<int> di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1};



template<class T>

bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



template<class T>

bool chmax(T& a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}



using S = ll;



S op(S a, S b) {return a + b;}

S e() {return 0;}



int main() {

    int t; cin >> t;

    rep(i, 0, t) {

        int n, x, y; cin >> n >> x >> y; x--; y--;

        vi ans(n, 0);

        rep(j, 0, n) {

            ans[j] = j % 2;

        }

        if(n % 2 == 1) ans[n - 1] = 2;

        if(ans[x] == ans[y]) {

            ans[max(x, y)] = 2;

            if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;}

        }

        rep(j, 0, n) cout << ans[j] << " ";

        cout << endl;

    }

}