답안 #682850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682850 2023-01-17T06:06:20 Z smartmonky 학교 설립 (IZhO13_school) C++14
15 / 100
326 ms 19588 KB
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
 
using namespace std;
 
const int N = 3e5 + 1;
 

vector <int> a, b;
vector <pair <int,int> > vp;
multiset <int> sta, stb;
int lm, ls, ans, s, m, n;
void solve(){
	for(int i = 0; i < n; i++){
		if(!s && !m)break;
		if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]) || stb.find(vp[i].ss) == stb.end())){
			//cout <<"1 " << vp[i].ff << endl;
			ans += vp[i].ff;
			if(sta.find(vp[i].ff) != sta.end())
				sta.erase(sta.find(vp[i].ff));
			if(stb.find(vp[i].ss) != stb.end()){
				stb.erase(stb.find(vp[i].ss));
				stb.insert(b[ls]);
			}
			ls++;
			m--;
		}else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]) || sta.find(vp[i].ff) == sta.end())){
			//cout <<"2 " << vp[i].ss << endl;
			ans += vp[i].ss;
			if(sta.find(vp[i].ff) != sta.end()){
				sta.erase(sta.find(vp[i].ff));
				sta.insert(a[lm]);
			}
			if(stb.find(vp[i].ss) != sta.end())
				stb.erase(stb.find(vp[i].ss));
			lm++;
			s--;
		}
	}
}
main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> s;
    vp.resize(n);
    for(int i = 0; i < n; i++){
		cin >> vp[i].ff >> vp[i].ss;
		a.pb(vp[i].ff);
		b.pb(vp[i].ss);
	}
	sort(rall(a));
	sort(rall(b));
	for(int i = 0; i < m; i++)
		sta.insert(a[i]);
	for(int i = 0; i < s; i++)
		stb.insert(b[i]);
	lm = m, ls = s;
	for(int i = 0;  i < 4; i++){
		sort(rall(vp));
		solve();
		for(int i = 0; i < n; i++)swap(vp[i].ff, vp[i].ss);
		solve();
	}
	cout << ans;
}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:22:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |   if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]) || stb.find(vp[i].ss) == stb.end())){
      |                                          ~~^~~~~
school.cpp:33:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   33 |   }else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]) || sta.find(vp[i].ff) == sta.end())){
      |                                                ~~~^~~~
school.cpp: At global scope:
school.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 4 ms 468 KB Output isn't correct
8 Incorrect 4 ms 596 KB Output isn't correct
9 Incorrect 4 ms 596 KB Output isn't correct
10 Incorrect 4 ms 596 KB Output isn't correct
11 Incorrect 6 ms 596 KB Output isn't correct
12 Incorrect 6 ms 596 KB Output isn't correct
13 Incorrect 36 ms 2928 KB Output isn't correct
14 Incorrect 73 ms 4180 KB Output isn't correct
15 Correct 115 ms 6056 KB Output is correct
16 Incorrect 301 ms 14348 KB Output isn't correct
17 Incorrect 326 ms 16000 KB Output isn't correct
18 Incorrect 235 ms 15932 KB Output isn't correct
19 Incorrect 324 ms 17560 KB Output isn't correct
20 Incorrect 288 ms 19588 KB Output isn't correct