Submission #750593

#TimeUsernameProblemLanguageResultExecution timeMemory
750593keta_tsimakuridzeNaan (JOI19_naan)C++14
100 / 100
1325 ms123316 KiB
#include<iostream>
#include<vector>
#include<set>
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
//#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, inf = 2e9; // !
int tot[N];
vector<pair<int, pair<int,int>> > x[N];
signed main() {
    int n, L;
    cin >> n >> L;

    for(int i = 1; i <= n; i++) {
        vector<int> v(L + 2);
        for(int j = 1; j <= L; j++) {
            cin >> v[j];
            tot[i] += v[j];
            v[j] *= n;
        }
        int k = 0, p = 0, all = 0;
        while((int)x[i].size() < n) {
            int cur = 0;
            if(v[k] - p >= tot[i]) {
                p += tot[i];
                x[i].push_back({k - 1, {p, v[k]}});
                if(p == v[k]) ++k, p = 0;
                continue;
            } else cur = v[k] - p, ++k;

            while(k <= L && cur + v[k] <= tot[i]) cur += v[k], ++k;
            p = tot[i] - cur;
            x[i].push_back({k - 1, {p, (p == 0 ? 1 : v[k])}});
        }
    }
    vector<int> f(n + 2), ans;
    int C = 0;
    for(int i = 0; i + 1 < n; i++) {
        int cur = 0;
        for(int j = 1; j <= n; j++) {

            if(f[j]) continue;
            if(!cur || x[j][i].f < x[cur][i].f || (x[j][i].f == x[cur][i].f && x[j][i].s.f * x[cur][i].s.s < x[cur][i].s.f * x[j][i].s.s)) cur = j;
        }
        f[cur] = 1;
        int g = __gcd(x[cur][i].s.f, x[cur][i].s.s);
        x[cur][i].s.f /= g; x[cur][i].s.s /= g;
        x[cur][i].s.f += x[cur][i].s.s * x[cur][i].f;
        assert(x[cur][i].s.s <= 1e9);
        cout << x[cur][i].s.f << " " << x[cur][i].s.s << "\n";
        ans.push_back(cur);
    }
    for(int i = 1; i <= n; i++) if(!f[i]) ans.push_back(i);
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";

}

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:25:27: warning: unused variable 'all' [-Wunused-variable]
   25 |         int k = 0, p = 0, all = 0;
      |                           ^~~
naan.cpp:58:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
      |                    ~~^~~~~~~~~~~~
naan.cpp:41:9: warning: unused variable 'C' [-Wunused-variable]
   41 |     int C = 0;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...