Submission #299757

# Submission time Handle Problem Language Result Execution time Memory
299757 2020-09-15T15:07:38 Z HynDuf Sails (IOI07_sails) C++11
25 / 100
1000 ms 65540 KB
#include <bits/stdc++.h>

#define task "S"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 2;
int n, h[N], num[N], cnt[N];
ll ans = 1e18, cur = 0;
void Try(int p)
{
    if (p > n)
    {
        ans = min(ans, cur);
        return;
    }
    vi a;
    rep(i, 1, h[p] - num[p]) a.eb(0);
    rep(i, 1, num[p]) a.eb(1);
    do
    {
        //PR(a, 0, h[p] - 1);
        rep(i, 0, h[p] - 1) if (a[i])
        {
            cnt[i + 1]++;
            cur += cnt[i + 1] - 1;
        }
        Try(p + 1);
        rep(i, 0, h[p] - 1) if (a[i])
        {
            cnt[i + 1]--;
            cur -= cnt[i + 1];
        }
    } while (next_permutation(all(a)));
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    rep(i, 1, n) cin >> h[i] >> num[i];
    Try(1);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 504 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 384 KB Output is correct
2 Correct 181 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 25976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 119 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 160 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 130 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 141 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -