# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
703960 |
2023-03-01T06:15:33 Z |
victor_gao |
Naan (JOI19_naan) |
C++17 |
|
35 ms |
9920 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(int x,int y,int 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';
}
};
int 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++){
int val; cin>>val;
arr[i][j]=val*n;
total[i]+=arr[i][j];
}
total[i]/=n;
}
for (int i=1;i<=n;i++){
int now=0;
for (int j=1;j<=l;j++){
int 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();
// cout<<i<<" : \n";
// for (auto j:cut[i])
// j.out();
// cout<<'\n';
}
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:61:29: warning: comparison of integer expressions of different signedness: 'std::vector<mixed>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
61 | assert(cut[i].size()==n);
| ~~~~~~~~~~~~~^~~
naan.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<mixed>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | 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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
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 |
340 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 |
340 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 |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
400 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
404 KB |
Output is correct |
21 |
Correct |
2 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 |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
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 |
340 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 |
340 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 |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
400 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
404 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
2 ms |
340 KB |
Output is correct |
43 |
Runtime error |
35 ms |
9920 KB |
Execution killed with signal 6 |
44 |
Halted |
0 ms |
0 KB |
- |