Submission #703969

# Submission time Handle Problem Language Result Execution time Memory
703969 2023-03-01T07:04:52 Z victor_gao Naan (JOI19_naan) C++17
100 / 100
678 ms 130312 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define pii pair<ll,ll>
#define x first
#define y second
#define N 2015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
struct mixed{
    ll a,b,c; // a+b/c
    mixed(ll x,ll y,ll z):a(x),b(y),c(z){}
    void reset(){
        while (b<0){ a--; b+=c; }
        while (b>=c){ a++; b-=c; }
        if (b>0&&c>0){
            ll g=__gcd(b,c);
            b/=g; c/=g;
        }
    }
    void out(){
        cout<<a*c+b<<" "<<c<<'\n';
    }
};
ll n,l,total[N],arr[N][N];
bool vis[N];
vector<mixed>cut[N];
bool bigger(mixed x,mixed y){
    if (x.a!=y.a) return x.a>y.a;
    return x.b*y.c>=x.c*y.b;
}
signed main(){
    fast
    cin>>n>>l;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=l;j++){
            ll val; cin>>val;
            arr[i][j]=val*n;
            total[i]+=arr[i][j]/n;
        }
    }
    for (int i=1;i<=n;i++){
        ll now=0;
        for (int j=1;j<=l;j++){
            ll last=arr[i][j];
            while (now+last>=total[i]){
                last-=(total[i]-now);
                now=0;
                cut[i].push_back(mixed(j-1,arr[i][j]-last,arr[i][j]));
            }
            now+=last;
        }
        assert(cut[i].size()==n);
        for (int j=0;j<cut[i].size();j++)
            cut[i][j].reset();
    }
    vector<mixed>ans;
    vector<int>order;
    for (int i=1;i<=n;i++){
        mixed mn=mixed(1e9,0,1);
        int use=0;
        for (int j=1;j<=n;j++){
            if (!vis[j]&&bigger(mn,cut[j][i-1])){
                mn=cut[j][i-1];
                use=j;
            }
        }
        vis[use]=1;
        order.push_back(use);
        ans.push_back(mn);
    }
    ans.pop_back();
    for (auto i:ans)
        i.out();
    for (auto j:order)
        cout<<j<<" ";
    cout<<'\n';
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from naan.cpp:3:
naan.cpp: In function 'int main()':
naan.cpp:60:29: warning: comparison of integer expressions of different signedness: 'std::vector<mixed>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |         assert(cut[i].size()==n);
      |                ~~~~~~~~~~~~~^~~
naan.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<mixed>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int j=0;j<cut[i].size();j++)
      |                      ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 388 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 396 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 380 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 448 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 388 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 396 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 392 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 380 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 396 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 448 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 63 ms 14924 KB Output is correct
44 Correct 356 ms 70208 KB Output is correct
45 Correct 146 ms 26208 KB Output is correct
46 Correct 18 ms 3588 KB Output is correct
47 Correct 220 ms 40064 KB Output is correct
48 Correct 483 ms 105652 KB Output is correct
49 Correct 112 ms 29720 KB Output is correct
50 Correct 588 ms 124184 KB Output is correct
51 Correct 216 ms 47616 KB Output is correct
52 Correct 503 ms 104248 KB Output is correct
53 Correct 456 ms 99340 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 233 ms 59688 KB Output is correct
56 Correct 295 ms 66588 KB Output is correct
57 Correct 245 ms 58592 KB Output is correct
58 Correct 419 ms 98580 KB Output is correct
59 Correct 247 ms 53184 KB Output is correct
60 Correct 623 ms 130312 KB Output is correct
61 Correct 627 ms 130188 KB Output is correct
62 Correct 676 ms 128780 KB Output is correct
63 Correct 635 ms 129280 KB Output is correct
64 Correct 629 ms 129472 KB Output is correct
65 Correct 678 ms 129252 KB Output is correct
66 Correct 655 ms 129456 KB Output is correct
67 Correct 589 ms 129296 KB Output is correct
68 Correct 258 ms 70340 KB Output is correct
69 Correct 248 ms 62152 KB Output is correct
70 Correct 315 ms 86184 KB Output is correct
71 Correct 388 ms 92304 KB Output is correct