답안 #707039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707039 2023-03-08T10:25:47 Z Antekb Naan (JOI19_naan) C++14
100 / 100
654 ms 150268 KB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
//#define deb(x...) ;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int K=20, N=1<<K, INF=1e9+5, mod2=1e9+7, mod=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint operator^(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=(*this)^(m/2);
		a*=a;
		return a*((*this)^(m&1));
	}
	modint odw(){
		return (*this)^((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}
vector<pair<pair<ll, ll>, int> > part[N];
int main(){
	//factinit();
	BOOST;
	int n, l;
	cin>>n>>l;
	for(int i=0; i<n; i++){
		ll sum=0;
		vi V(l);
		for(int j=0; j<l; j++){
			cin>>V[j];
			sum+=V[j];
			V[j]*=n;
		}
		int wsk=1;
		ll sum2=0;
		//deb(sum);
		for(int j=0; j<l; j++){
			int z=0;
			while(sum2+V[j]>=wsk*sum){
				int zz=wsk*sum-sum2;
				//deb(zz);
				part[wsk].pb(mp(mp(j*1ll*V[j]+zz, V[j]), i));
				//deb(part[wsk].back());
				z=zz;
				wsk++;
			}
			sum2+=V[j];
		}
	}
	vi uzy(n);
	vi ans;
	for(int i=1; i<=n; i++){
		//deb(part[i]);
		sort(part[i].begin(), part[i].end(), [](pair<pair<ll, ll>, int> a, pair<pair<ll, ll>, int> b){
			if(__int128(a.st.st)*b.st.nd==__int128(a.st.nd)*b.st.st)return a.nd<b.nd;
			return __int128(a.st.st)*b.st.nd<__int128(a.st.nd)*b.st.st;
		});
		for(int j=0; j<n; j++){
			if(!uzy[part[i][j].nd]){
				ans.pb(part[i][j].nd);
				uzy[part[i][j].nd]=1;
				if(i!=n)cout<<part[i][j].st.st<<" "<<part[i][j].st.nd<<"\n";
				break;
			}
		}
	}
	for(int i:ans)cout<<i+1<<" ";
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:136:8: warning: variable 'z' set but not used [-Wunused-but-set-variable]
  136 |    int z=0;
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 17 ms 33108 KB Output is correct
3 Correct 16 ms 33180 KB Output is correct
4 Correct 16 ms 33108 KB Output is correct
5 Correct 15 ms 33160 KB Output is correct
6 Correct 16 ms 33108 KB Output is correct
7 Correct 16 ms 33056 KB Output is correct
8 Correct 16 ms 33152 KB Output is correct
9 Correct 17 ms 33108 KB Output is correct
10 Correct 17 ms 33108 KB Output is correct
11 Correct 16 ms 33136 KB Output is correct
12 Correct 16 ms 33168 KB Output is correct
13 Correct 16 ms 33168 KB Output is correct
14 Correct 16 ms 33072 KB Output is correct
15 Correct 15 ms 33156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 33048 KB Output is correct
2 Correct 15 ms 33108 KB Output is correct
3 Correct 16 ms 33160 KB Output is correct
4 Correct 15 ms 33108 KB Output is correct
5 Correct 16 ms 33056 KB Output is correct
6 Correct 15 ms 33108 KB Output is correct
7 Correct 15 ms 33108 KB Output is correct
8 Correct 16 ms 33160 KB Output is correct
9 Correct 15 ms 33136 KB Output is correct
10 Correct 15 ms 33108 KB Output is correct
11 Correct 15 ms 33140 KB Output is correct
12 Correct 15 ms 33032 KB Output is correct
13 Correct 16 ms 33108 KB Output is correct
14 Correct 17 ms 33128 KB Output is correct
15 Correct 19 ms 33064 KB Output is correct
16 Correct 19 ms 33176 KB Output is correct
17 Correct 16 ms 33168 KB Output is correct
18 Correct 16 ms 33168 KB Output is correct
19 Correct 16 ms 33108 KB Output is correct
20 Correct 17 ms 33160 KB Output is correct
21 Correct 16 ms 33164 KB Output is correct
22 Correct 18 ms 33228 KB Output is correct
23 Correct 16 ms 33064 KB Output is correct
24 Correct 19 ms 33188 KB Output is correct
25 Correct 17 ms 33108 KB Output is correct
26 Correct 16 ms 33160 KB Output is correct
27 Correct 16 ms 33164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 17 ms 33108 KB Output is correct
3 Correct 16 ms 33180 KB Output is correct
4 Correct 16 ms 33108 KB Output is correct
5 Correct 15 ms 33160 KB Output is correct
6 Correct 16 ms 33108 KB Output is correct
7 Correct 16 ms 33056 KB Output is correct
8 Correct 16 ms 33152 KB Output is correct
9 Correct 17 ms 33108 KB Output is correct
10 Correct 17 ms 33108 KB Output is correct
11 Correct 16 ms 33136 KB Output is correct
12 Correct 16 ms 33168 KB Output is correct
13 Correct 16 ms 33168 KB Output is correct
14 Correct 16 ms 33072 KB Output is correct
15 Correct 15 ms 33156 KB Output is correct
16 Correct 16 ms 33048 KB Output is correct
17 Correct 15 ms 33108 KB Output is correct
18 Correct 16 ms 33160 KB Output is correct
19 Correct 15 ms 33108 KB Output is correct
20 Correct 16 ms 33056 KB Output is correct
21 Correct 15 ms 33108 KB Output is correct
22 Correct 15 ms 33108 KB Output is correct
23 Correct 16 ms 33160 KB Output is correct
24 Correct 15 ms 33136 KB Output is correct
25 Correct 15 ms 33108 KB Output is correct
26 Correct 15 ms 33140 KB Output is correct
27 Correct 15 ms 33032 KB Output is correct
28 Correct 16 ms 33108 KB Output is correct
29 Correct 17 ms 33128 KB Output is correct
30 Correct 19 ms 33064 KB Output is correct
31 Correct 19 ms 33176 KB Output is correct
32 Correct 16 ms 33168 KB Output is correct
33 Correct 16 ms 33168 KB Output is correct
34 Correct 16 ms 33108 KB Output is correct
35 Correct 17 ms 33160 KB Output is correct
36 Correct 16 ms 33164 KB Output is correct
37 Correct 18 ms 33228 KB Output is correct
38 Correct 16 ms 33064 KB Output is correct
39 Correct 19 ms 33188 KB Output is correct
40 Correct 17 ms 33108 KB Output is correct
41 Correct 16 ms 33160 KB Output is correct
42 Correct 16 ms 33164 KB Output is correct
43 Correct 62 ms 46288 KB Output is correct
44 Correct 312 ms 100820 KB Output is correct
45 Correct 150 ms 55860 KB Output is correct
46 Correct 31 ms 34636 KB Output is correct
47 Correct 244 ms 64920 KB Output is correct
48 Correct 390 ms 125408 KB Output is correct
49 Correct 120 ms 55188 KB Output is correct
50 Correct 519 ms 133828 KB Output is correct
51 Correct 215 ms 76876 KB Output is correct
52 Correct 450 ms 119560 KB Output is correct
53 Correct 391 ms 115488 KB Output is correct
54 Correct 17 ms 33108 KB Output is correct
55 Correct 230 ms 93568 KB Output is correct
56 Correct 267 ms 90956 KB Output is correct
57 Correct 235 ms 85224 KB Output is correct
58 Correct 364 ms 115788 KB Output is correct
59 Correct 216 ms 81004 KB Output is correct
60 Correct 564 ms 149320 KB Output is correct
61 Correct 526 ms 150268 KB Output is correct
62 Correct 654 ms 146384 KB Output is correct
63 Correct 586 ms 145684 KB Output is correct
64 Correct 568 ms 146000 KB Output is correct
65 Correct 426 ms 138272 KB Output is correct
66 Correct 461 ms 138396 KB Output is correct
67 Correct 527 ms 138476 KB Output is correct
68 Correct 220 ms 97724 KB Output is correct
69 Correct 244 ms 91632 KB Output is correct
70 Correct 272 ms 109888 KB Output is correct
71 Correct 323 ms 115532 KB Output is correct