답안 #524651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524651 2022-02-09T18:11:46 Z fatemetmhr Naan (JOI19_naan) C++17
컴파일 오류
0 ms 0 KB
//  ~Be name khoda~  //
 
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb       push_back
#define mp       make_pair
#define fi       first
#define se       second
#define cl       clear
 
const int maxn  =  1e6   + 10;
const int maxn5 =  2e3   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  2e18;
 
struct kasr{
	 s, m;
	kasr(__int128 a, __int128 b){
		__int128 g = __gcd(a, b);
		s = a / g;
		m = b / g;
	}
	kasr(){
		s = 0;
		m = 1;
	}
	
	inline ll ciel(){
		__int128 f = s / m;
		if(s * f != m)
			f++;
		return f;
	}
	
};
 
 
 
inline kasr operator -(ll, kasr b){
	a *= b.m;
	return kasr(a - b.s, b.m);
}
inline kasr operator -(kasr a, kasr b){
	__int128 mm = a.m * b.m / __gcd(a.m, b.m);
	return kasr(a.s * (mm / a.m) - b.s * (mm / b.m), mm);
}
inline kasr operator +(kasr a, kasr b){
	__int128 mm = a.m * b.m / __gcd(a.m, b.m);
	return kasr(a.s * (mm / a.m) + b.s * (mm / b.m), mm);
}
inline bool operator <=(kasr a, kasr b){
	return a.s * b.m <= b.s * a.m;
}
inline bool operator >=(kasr a, kasr b){
	return a.s * b.m >= b.s * a.m;
}
inline bool operator <(kasr a, kasr b){
	return a.s * b.m < b.s * a.m;
}
inline bool operator >(kasr a, kasr b){
	return a.s * b.m > b.s * a.m;
}
 
 
 
int n, l, per[maxn5];
ll a[maxn5][maxn5], ps[maxn5][maxn5];
kasr out[maxn5], have[maxn5][maxn5];
bool mark[maxn5];
 
 
 
inline ll get_val(int l, int r, int i){
	if(l >= r)
		return 0;
	return ps[i][r] - ps[i][l];
}
 
inline kasr cont(int i, kasr last, kasr ask){
	//cout << "starting " << i << ' ' << last.s << ' ' << last.m << '\n';
	kasr ret (0, 1);
	int id = last.ciel();
	if(kasr(id, 1) > last){
		kasr rem = id - last;
		kasr sup = kasr(ask.s, ask.m * a[i][id]);
		if(sup >= rem){
			last = kasr(id, 1);
			ask = ask - kasr(rem.s * a[i][id], rem.m);
		}
		else{
			return last + sup;
		}
	}
	int lo = id, hi = l + 1;
	while(hi - lo > 1){
		int mid = (lo + hi) >> 1;
		if(kasr(get_val(id, mid, i), 1) <= ask)
			lo = mid;
		else
			hi = mid;
	}
	//cout << "ok " << lo << endl;
	last = kasr(lo, 1);
	ask = ask - kasr(get_val(id, lo, i), 1);
	if(ask.s == 0)
		return last;
	kasr sup = kasr(ask.s, ask.m * a[i][lo + 1]);
	//cout << ask.s << ' ' << ask.m << endl;
	return last + sup;
}
 
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
	cin >> n >> l;
	
	for(int i = 0; i < n; i++){
		ll sum = 0;
		for(int j = 1; j <= l; j++){
			cin >> a[i][j];
			ps[i][j] = a[i][j] + ps[i][j - 1];
			sum += a[i][j];
		}
		
		kasr last(0, 1);
		for(int j = 0; j < n; j++){
			//cout << i << ' ' << j << ' ' << last.s << ' ' << last.m << ' ' << sum << '\n';
			last = have[i][j] = cont(i, last, kasr(sum, n));
		}
	}
	
	//cout << have[1][0].s << ' ' << have[1][0].m << endl;
	
	for(int i = 0; i < n - 1; i++){
		out[i] = kasr(l + 5, 1);
		per[i] = -1;
		for(int j = 0; j < n; j++) 
			if(!mark[j] && have[j][i] < out[i]){
				out[i] = have[j][i];
				//cout << i << ' ' << j << ' ' << out[i].s << ' ' << out[i].m << endl;
				if(per[i] != -1)
					mark[per[i]] = false;
				per[i] = j;
				mark[j] = true;
			}
		cout << ll(out[i].s) << ' ' << ll(out[i].m) << '\n';
	}
	for(int i = 0; i < n; i++) if(!mark[i])
		per[n - 1] = i;
	for(int i = 0; i < n; i++){
		cout << per[i] + 1 << ' ';
	}
	cout << endl;
}
















Compilation message

naan.cpp:23:3: error: 's' does not name a type; did you mean 'se'?
   23 |   s, m;
      |   ^
      |   se
naan.cpp: In constructor 'kasr::kasr(__int128, __int128)':
naan.cpp:26:3: error: 's' was not declared in this scope
   26 |   s = a / g;
      |   ^
naan.cpp:27:3: error: 'm' was not declared in this scope; did you mean 'tm'?
   27 |   m = b / g;
      |   ^
      |   tm
naan.cpp: In constructor 'kasr::kasr()':
naan.cpp:30:3: error: 's' was not declared in this scope; did you mean 'se'?
   30 |   s = 0;
      |   ^
      |   se
naan.cpp:31:3: error: 'm' was not declared in this scope; did you mean 'tm'?
   31 |   m = 1;
      |   ^
      |   tm
naan.cpp: In member function 'll kasr::ciel()':
naan.cpp:35:16: error: 's' was not declared in this scope
   35 |   __int128 f = s / m;
      |                ^
naan.cpp:35:20: error: 'm' was not declared in this scope; did you mean 'tm'?
   35 |   __int128 f = s / m;
      |                    ^
      |                    tm
naan.cpp: In function 'kasr operator-(ll, kasr)':
naan.cpp:46:2: error: 'a' was not declared in this scope
   46 |  a *= b.m;
      |  ^
naan.cpp:46:9: error: 'struct kasr' has no member named 'm'
   46 |  a *= b.m;
      |         ^
naan.cpp:47:20: error: 'struct kasr' has no member named 's'
   47 |  return kasr(a - b.s, b.m);
      |                    ^
naan.cpp:47:25: error: 'struct kasr' has no member named 'm'
   47 |  return kasr(a - b.s, b.m);
      |                         ^
naan.cpp: In function 'kasr operator-(kasr, kasr)':
naan.cpp:50:18: error: 'struct kasr' has no member named 'm'
   50 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                  ^
naan.cpp:50:24: error: 'struct kasr' has no member named 'm'
   50 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                        ^
naan.cpp:50:36: error: 'struct kasr' has no member named 'm'
   50 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                                    ^
naan.cpp:50:41: error: 'struct kasr' has no member named 'm'
   50 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                                         ^
naan.cpp:51:16: error: 'struct kasr' has no member named 's'
   51 |  return kasr(a.s * (mm / a.m) - b.s * (mm / b.m), mm);
      |                ^
naan.cpp:51:28: error: 'struct kasr' has no member named 'm'
   51 |  return kasr(a.s * (mm / a.m) - b.s * (mm / b.m), mm);
      |                            ^
naan.cpp:51:35: error: 'struct kasr' has no member named 's'
   51 |  return kasr(a.s * (mm / a.m) - b.s * (mm / b.m), mm);
      |                                   ^
naan.cpp:51:47: error: 'struct kasr' has no member named 'm'
   51 |  return kasr(a.s * (mm / a.m) - b.s * (mm / b.m), mm);
      |                                               ^
naan.cpp: In function 'kasr operator+(kasr, kasr)':
naan.cpp:54:18: error: 'struct kasr' has no member named 'm'
   54 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                  ^
naan.cpp:54:24: error: 'struct kasr' has no member named 'm'
   54 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                        ^
naan.cpp:54:36: error: 'struct kasr' has no member named 'm'
   54 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                                    ^
naan.cpp:54:41: error: 'struct kasr' has no member named 'm'
   54 |  __int128 mm = a.m * b.m / __gcd(a.m, b.m);
      |                                         ^
naan.cpp:55:16: error: 'struct kasr' has no member named 's'
   55 |  return kasr(a.s * (mm / a.m) + b.s * (mm / b.m), mm);
      |                ^
naan.cpp:55:28: error: 'struct kasr' has no member named 'm'
   55 |  return kasr(a.s * (mm / a.m) + b.s * (mm / b.m), mm);
      |                            ^
naan.cpp:55:35: error: 'struct kasr' has no member named 's'
   55 |  return kasr(a.s * (mm / a.m) + b.s * (mm / b.m), mm);
      |                                   ^
naan.cpp:55:47: error: 'struct kasr' has no member named 'm'
   55 |  return kasr(a.s * (mm / a.m) + b.s * (mm / b.m), mm);
      |                                               ^
naan.cpp: In function 'bool operator<=(kasr, kasr)':
naan.cpp:58:11: error: 'struct kasr' has no member named 's'
   58 |  return a.s * b.m <= b.s * a.m;
      |           ^
naan.cpp:58:17: error: 'struct kasr' has no member named 'm'
   58 |  return a.s * b.m <= b.s * a.m;
      |                 ^
naan.cpp:58:24: error: 'struct kasr' has no member named 's'
   58 |  return a.s * b.m <= b.s * a.m;
      |                        ^
naan.cpp:58:30: error: 'struct kasr' has no member named 'm'
   58 |  return a.s * b.m <= b.s * a.m;
      |                              ^
naan.cpp: In function 'bool operator>=(kasr, kasr)':
naan.cpp:61:11: error: 'struct kasr' has no member named 's'
   61 |  return a.s * b.m >= b.s * a.m;
      |           ^
naan.cpp:61:17: error: 'struct kasr' has no member named 'm'
   61 |  return a.s * b.m >= b.s * a.m;
      |                 ^
naan.cpp:61:24: error: 'struct kasr' has no member named 's'
   61 |  return a.s * b.m >= b.s * a.m;
      |                        ^
naan.cpp:61:30: error: 'struct kasr' has no member named 'm'
   61 |  return a.s * b.m >= b.s * a.m;
      |                              ^
naan.cpp: In function 'bool operator<(kasr, kasr)':
naan.cpp:64:11: error: 'struct kasr' has no member named 's'
   64 |  return a.s * b.m < b.s * a.m;
      |           ^
naan.cpp:64:17: error: 'struct kasr' has no member named 'm'
   64 |  return a.s * b.m < b.s * a.m;
      |                 ^
naan.cpp:64:23: error: 'struct kasr' has no member named 's'
   64 |  return a.s * b.m < b.s * a.m;
      |                       ^
naan.cpp:64:29: error: 'struct kasr' has no member named 'm'
   64 |  return a.s * b.m < b.s * a.m;
      |                             ^
naan.cpp: In function 'bool operator>(kasr, kasr)':
naan.cpp:67:11: error: 'struct kasr' has no member named 's'
   67 |  return a.s * b.m > b.s * a.m;
      |           ^
naan.cpp:67:17: error: 'struct kasr' has no member named 'm'
   67 |  return a.s * b.m > b.s * a.m;
      |                 ^
naan.cpp:67:23: error: 'struct kasr' has no member named 's'
   67 |  return a.s * b.m > b.s * a.m;
      |                       ^
naan.cpp:67:29: error: 'struct kasr' has no member named 'm'
   67 |  return a.s * b.m > b.s * a.m;
      |                             ^
naan.cpp: In function 'kasr cont(int, kasr, kasr)':
naan.cpp:91:23: error: 'struct kasr' has no member named 's'
   91 |   kasr sup = kasr(ask.s, ask.m * a[i][id]);
      |                       ^
naan.cpp:91:30: error: 'struct kasr' has no member named 'm'
   91 |   kasr sup = kasr(ask.s, ask.m * a[i][id]);
      |                              ^
naan.cpp:94:25: error: 'struct kasr' has no member named 's'
   94 |    ask = ask - kasr(rem.s * a[i][id], rem.m);
      |                         ^
naan.cpp:94:43: error: 'struct kasr' has no member named 'm'
   94 |    ask = ask - kasr(rem.s * a[i][id], rem.m);
      |                                           ^
naan.cpp:111:9: error: 'struct kasr' has no member named 's'
  111 |  if(ask.s == 0)
      |         ^
naan.cpp:113:22: error: 'struct kasr' has no member named 's'
  113 |  kasr sup = kasr(ask.s, ask.m * a[i][lo + 1]);
      |                      ^
naan.cpp:113:29: error: 'struct kasr' has no member named 'm'
  113 |  kasr sup = kasr(ask.s, ask.m * a[i][lo + 1]);
      |                             ^
naan.cpp: In function 'int main()':
naan.cpp:153:21: error: 'struct kasr' has no member named 's'
  153 |   cout << ll(out[i].s) << ' ' << ll(out[i].m) << '\n';
      |                     ^
naan.cpp:153:44: error: 'struct kasr' has no member named 'm'
  153 |   cout << ll(out[i].s) << ' ' << ll(out[i].m) << '\n';
      |                                            ^