Submission #921794

# Submission time Handle Problem Language Result Execution time Memory
921794 2024-02-04T10:22:31 Z boris_mihov Naan (JOI19_naan) C++17
100 / 100
3604 ms 182516 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
 
typedef long long llong;
const int MAXN = 2000 + 10;
const int INF = 1e9;
 
int n, l;
struct Fraction
{
    __int128 p;    
    __int128 q;
    Fraction()
    {
        p = 0;
        q = 1;
    }    
 
    Fraction(__int128 _p, __int128 _q = 1)
    {
        p = _p;
        q = _q;
        __int128 g = std::__gcd(p, q);
        p /= g; q /= g;
    }
 
    friend Fraction operator + (const Fraction &left, const Fraction &right)
    {
        return {left.p * right.q + right.p * left.q, left.q * right.q};
    }
 
    friend Fraction operator - (const Fraction &left, const Fraction &right)
    {
        return {left.p * right.q - right.p * left.q, left.q * right.q};
    }
 
    friend Fraction operator * (const Fraction &left, const Fraction &right)
    {
        return {left.p * right.p, left.q * right.q};
    }
 
    friend Fraction operator / (const Fraction &left, const Fraction &right)
    {
        return {left.p * right.q, left.q * right.p};
    }
 
    friend void operator += (Fraction &left, const Fraction &right)
    {
        left = left + right;
    }
 
    friend void operator -= (Fraction &left, const Fraction &right)
    {
        left = left - right;
    }
 
    friend void operator *= (Fraction &left, const Fraction &right)
    {
        left = left * right;
    }
    
    friend void operator /= (Fraction &left, const Fraction &right)
    {
        left = left / right;
    }
 
    friend bool operator < (const Fraction &left, const Fraction &right)
    {
        return (left.p * right.q < right.p * left.q);
    }
 
    friend bool operator <= (const Fraction &left, const Fraction &right)
    {
        return (left.p * right.q <= right.p * left.q);
    }
 
    void print()
    {
        std::cout << (llong)p << ' ' << (llong)q << '\n';
    }
};
 
bool taken[MAXN];
Fraction s[MAXN];
llong v[MAXN][MAXN];
std::vector <Fraction> positions[MAXN];
std::vector <Fraction> answer;
std::vector <int> order;
 
void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        Fraction takenTo = 0;
        Fraction nextSum = 0;
        Fraction currentSum = 0;

        for (int pos = 1 ; pos <= l && positions[i].size() < n ; ++pos)
        {
            nextSum = currentSum + (1 - takenTo) * v[i][pos];
            if (s[i] <= nextSum)
            {
                Fraction breakAt = pos - 1 + takenTo + (s[i] - currentSum) / v[i][pos];
                positions[i].push_back(breakAt);
                takenTo = breakAt - pos + 1;
                currentSum = 0;
                pos--;
            } else
            {
                currentSum = nextSum;
                takenTo = 0;
            }
        }
    }
    
    for (int i = 0 ; i < n ; ++i)
    {
        int minIdx = -1;
        for (int j = 1 ; j <= n ; ++j)
        {
            if (taken[j])
            {
                continue;
            }

            if (minIdx == -1 || positions[j][i] < positions[minIdx][i])
            {
                minIdx = j;
            }
        }

        answer.push_back(positions[minIdx][i]);
        order.push_back(minIdx);
        taken[minIdx] = true;
    }
}
 
void print()
{
    for (int i = 0 ; i < n - 1 ; ++i)
    {
        answer[i].print();
    }
 
    for (int i = 0 ; i < n ; ++i)
    {
        std::cout << order[i] << ' ';
    }
 
    std::cout << '\n';
}
 
void input()
{
    std::cin >> n >> l;
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j <= l ; ++j)
        {
            std::cin >> v[i][j];
            s[i] += v[i][j];
        }
        
        s[i] /= n;
    }
}
 
void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}
 
int main()
{
    fastIOI();
    input();
    solve();
    print();
 
    return 0;
}

Compilation message

naan.cpp: In function 'void solve()':
naan.cpp:101:60: warning: comparison of integer expressions of different signedness: 'std::vector<Fraction>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |         for (int pos = 1 ; pos <= l && positions[i].size() < n ; ++pos)
      |                                        ~~~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 584 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 584 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 432 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 276 ms 23176 KB Output is correct
44 Correct 1638 ms 97288 KB Output is correct
45 Correct 502 ms 38224 KB Output is correct
46 Correct 48 ms 4180 KB Output is correct
47 Correct 933 ms 56592 KB Output is correct
48 Correct 2795 ms 151120 KB Output is correct
49 Correct 572 ms 42872 KB Output is correct
50 Correct 3275 ms 164072 KB Output is correct
51 Correct 1043 ms 58992 KB Output is correct
52 Correct 2624 ms 135356 KB Output is correct
53 Correct 2472 ms 127916 KB Output is correct
54 Correct 2 ms 600 KB Output is correct
55 Correct 1339 ms 91200 KB Output is correct
56 Correct 1444 ms 83176 KB Output is correct
57 Correct 1200 ms 75284 KB Output is correct
58 Correct 2224 ms 128816 KB Output is correct
59 Correct 1232 ms 67172 KB Output is correct
60 Correct 2690 ms 182372 KB Output is correct
61 Correct 2880 ms 182248 KB Output is correct
62 Correct 3329 ms 181760 KB Output is correct
63 Correct 3256 ms 182516 KB Output is correct
64 Correct 2826 ms 182368 KB Output is correct
65 Correct 3604 ms 169028 KB Output is correct
66 Correct 3474 ms 168996 KB Output is correct
67 Correct 2892 ms 169140 KB Output is correct
68 Correct 1282 ms 94712 KB Output is correct
69 Correct 1100 ms 81952 KB Output is correct
70 Correct 1687 ms 117780 KB Output is correct
71 Correct 1877 ms 123992 KB Output is correct