/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB
#3 Wrong Answer 2ms 540.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
/// Welcome to Nasif's Code
#define bug(var) cout << #var << " " << var << endl;
#define all(q) (q).begin(), (q).end()
#define FastRead             \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
const int MOD = (int)998244353;
const int MAX = 1e6;
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
int arr[50];
int solve(int dif, int n)
{
    queue<int> q;
    map<int, int> mp;
    vector<pair<int, int>> grp;
    for (int i = 0; i < n; i++)
        mp[arr[i]]++;
    for (int i = 0; i < n; i++)
    {
        int x = arr[i];
        if (mp[x] == 0)
            continue;
        mp[x]--;
        int y = x + dif;
        if (mp[y] == 0)
            q.push(x);
        else
        {
            mp[y]--;
            grp.push_back({x, y});
        }
    }
    if (q.empty())
        return grp.size();
    int qsz = q.size();
    int gsz = grp.size();
    if (qsz % gsz)
        return 0;
    int part = qsz / gsz;
    for (auto it : grp)
    {
        int l = it.first;
        int r = it.second;
        for (int i = 0; i < part; i++)
        {
            int x = q.front();
            q.pop();
            if (x < l || x > r)
                return 0;
        }
    }
    return grp.size();
}
void ignite()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    set<int> dif;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            dif.insert(arr[j] - arr[i]);
    int ans = 1;
    for (auto it : dif)
        ans = max(ans, solve(it, n));
    cout << ans << endl;
}
int main()
{
    FastRead
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        int tc = 1;
    cin >> tc;
    while (tc--)
        ignite();

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1162 Roy and Maximum Partition
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-10 17:41:40
Judged At
2025-02-10 17:41:40
Judged By
Score
0
Total Time
2ms
Peak Memory
540.0 KiB