답안 #591850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591850 2022-07-08T03:42:22 Z Loki_Nguyen Drvca (COCI19_drvca) C++14
0 / 110
86 ms 19056 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, int>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
const int N = 3e5 + 3;
const int M = 1 << 24;
const int mod = 1e9 + 7;
const int base = 300;
const ll inf = 1e12;
int pw(int k, int n)
{
    int total = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
int m, n, t, k, a[N], ans, b[N], c[N];
vector<int> adj[N], L, R;
multiset<int> st, cur;
bool check(int s, int d)
{
    L.clear();
    R.clear();
    st = cur;
    while (!st.empty())
    {
        if (st.find(s) == st.end())
            break;
        L.pb(s);
        st.erase(st.find(s));
        s += d;
    }
    if (st.size() <= 1)
    {
        if (!st.empty())
            R.pb(*st.begin());
        return true;
    }
    s = (*st.begin());
    R.pb(s);
    st.erase(st.begin());
    d = (*st.begin()) - s;
    while (!st.empty())
    {
        s += d;
        R.pb(s);
        if (*st.begin() != s)
            return false;
        st.erase(st.begin());
    }
    return true;
}
void sol()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cur.insert(a[i]);
    }
    sort(a + 1, a + 1 + n);
    if (check(a[1], a[2] - a[1]))
    {
        if (R.empty())
        {
            R.pb(L.back());
            L.pop_back();
        }
    }
    else if (check(a[1], a[3] - a[1]))
    {
        if (R.empty())
        {
            R.pb(L.back());
            L.pop_back();
        }
    }
    else if (check(a[2], a[3] - a[2]))
    {
        if (R.empty())
        {
            R.pb(L.back());
            L.pop_back();
        }
    }
    else
    {
        cout << -1;
        return;
    }
    cout << L.size() << '\n';
    for (int x : L)
        cout << x << " ";
    cout << '\n';
    cout << R.size() << '\n';
    for (int x : R)
        cout << x << " ";
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
#define task "tests"
    if (fopen(task ".inp", "r"))
    {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int ntest = 1;
    // cin >> ntest;
    while (ntest-- > 0)
        sol();
}

Compilation message

drvca.cpp: In function 'int32_t main()':
drvca.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
drvca.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7400 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 4 ms 7336 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7400 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 4 ms 7336 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 19056 KB Output is correct
2 Correct 68 ms 18432 KB Output is correct
3 Correct 71 ms 19016 KB Output is correct
4 Correct 86 ms 18480 KB Output is correct
5 Correct 81 ms 19056 KB Output is correct
6 Correct 68 ms 18476 KB Output is correct
7 Correct 74 ms 19008 KB Output is correct
8 Correct 69 ms 18508 KB Output is correct
9 Incorrect 79 ms 18480 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7400 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Incorrect 4 ms 7336 KB Output isn't correct
10 Halted 0 ms 0 KB -