답안 #722049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722049 2023-04-11T11:00:58 Z PoPularPlusPlus Brunhilda’s Birthday (BOI13_brunhilda) C++17
3.33333 / 100
264 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

bool remender(ll a , ll b){return a%b;}

//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);

const int N = 10000002;
vector<int> v[N];

void solve(){
	int n , qu;
	cin >> n >> qu;
	int arr[n];
	for(int i = 0; i < n; i++)cin >> arr[i];
	vector<pair<int,int>> queries(qu);
	for(int i = 0; i < qu; i++){
		cin >> queries[i].vf;
		queries[i].vs = i;
	}
	sort(all(queries));
	int mx = 0;
	for(int i = 0; i < n; i++)mx = max(mx , arr[i]);
	for(int i = 0; i < n; i++){
		for(int j = arr[i]; j <= N-2; j+=arr[i]){
			v[j].pb(i);
		}
	}
	int cur[n];
	queue<pair<int,int>> q;
	for(int i = 0; i < n; i++){
		cur[i] = 0;
		q.push(mp(0,i));
	}
	int ans[qu];
	int pointer = 0;
	for(int i = 1; i <= N-2 && pointer < queries.size(); i++){
		for(int j : v[i]){
			cur[j] = -1e9;
		}
		while(q.size()){
			pair<int,int> p = q.front();
			if(cur[p.vs] == p.vf)break;
			q.pop();
		}
		while(pointer < queries.size()){
			if(queries[pointer].vf == i){
				ans[queries[pointer].vs] = (q.size() ? q.front().vf+1 : 1e9);
			}
			else break;
			pointer++;
		}
		int res = 1e9;
		if(q.size())res = q.front().vf+1;
		//cout << res << ' ';
		for(int j : v[i]){
			if(cur[j] == -1e9){
				q.push(mp(res,j));
				cur[j] = res;
			}
		}
	}
	for(int i = 0; i < qu; i++){
		if(ans[i] >= 1e9)cout << "oo\n";
		else cout << ans[i] << '\n';
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   // int t;cin>>t;
   // while(t--){
		solve();
	//}
	return 0;
}

Compilation message

brunhilda.cpp: In function 'void solve()':
brunhilda.cpp:53:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i = 1; i <= N-2 && pointer < queries.size(); i++){
      |                             ~~~~~~~~^~~~~~~~~~~~~~~~
brunhilda.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   while(pointer < queries.size()){
      |         ~~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 262144 KB Execution killed with signal 9
2 Runtime error 118 ms 262144 KB Execution killed with signal 9
3 Runtime error 128 ms 262144 KB Execution killed with signal 9
4 Correct 223 ms 258432 KB Output is correct
5 Runtime error 136 ms 262144 KB Execution killed with signal 9
6 Runtime error 119 ms 262144 KB Execution killed with signal 9
7 Runtime error 129 ms 262144 KB Execution killed with signal 9
8 Runtime error 121 ms 262144 KB Execution killed with signal 9
9 Runtime error 143 ms 262144 KB Execution killed with signal 9
10 Runtime error 122 ms 262144 KB Execution killed with signal 9
11 Runtime error 126 ms 262144 KB Execution killed with signal 9
12 Correct 226 ms 251804 KB Output is correct
13 Runtime error 121 ms 262144 KB Execution killed with signal 9
14 Runtime error 123 ms 262144 KB Execution killed with signal 9
15 Runtime error 120 ms 262144 KB Execution killed with signal 9
16 Runtime error 120 ms 262144 KB Execution killed with signal 9
17 Runtime error 142 ms 262144 KB Execution killed with signal 9
18 Correct 244 ms 258488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 189 ms 262144 KB Execution killed with signal 9
2 Runtime error 152 ms 262144 KB Execution killed with signal 9
3 Runtime error 126 ms 262144 KB Execution killed with signal 9
4 Runtime error 135 ms 262144 KB Execution killed with signal 9
5 Runtime error 130 ms 262144 KB Execution killed with signal 9
6 Runtime error 126 ms 262144 KB Execution killed with signal 9
7 Runtime error 199 ms 262144 KB Execution killed with signal 9
8 Runtime error 127 ms 262144 KB Execution killed with signal 9
9 Runtime error 127 ms 262144 KB Execution killed with signal 9
10 Runtime error 136 ms 262144 KB Execution killed with signal 9
11 Runtime error 129 ms 262144 KB Execution killed with signal 9
12 Runtime error 127 ms 262144 KB Execution killed with signal 9
13 Runtime error 148 ms 262144 KB Execution killed with signal 9
14 Runtime error 124 ms 262144 KB Execution killed with signal 9
15 Runtime error 129 ms 262144 KB Execution killed with signal 9
16 Runtime error 151 ms 262144 KB Execution killed with signal 9
17 Runtime error 130 ms 262144 KB Execution killed with signal 9
18 Runtime error 122 ms 262144 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 134 ms 262144 KB Execution killed with signal 9
2 Runtime error 132 ms 262144 KB Execution killed with signal 9
3 Runtime error 127 ms 262144 KB Execution killed with signal 9
4 Runtime error 149 ms 262144 KB Execution killed with signal 9
5 Runtime error 264 ms 262144 KB Execution killed with signal 9
6 Runtime error 140 ms 262144 KB Execution killed with signal 9
7 Runtime error 138 ms 262144 KB Execution killed with signal 9
8 Runtime error 128 ms 262144 KB Execution killed with signal 9
9 Runtime error 128 ms 262144 KB Execution killed with signal 9
10 Runtime error 119 ms 262144 KB Execution killed with signal 9
11 Runtime error 128 ms 262144 KB Execution killed with signal 9
12 Runtime error 128 ms 262144 KB Execution killed with signal 9
13 Runtime error 131 ms 262144 KB Execution killed with signal 9
14 Runtime error 126 ms 262144 KB Execution killed with signal 9
15 Runtime error 120 ms 262144 KB Execution killed with signal 9
16 Runtime error 124 ms 262144 KB Execution killed with signal 9
17 Runtime error 140 ms 262144 KB Execution killed with signal 9
18 Runtime error 129 ms 262144 KB Execution killed with signal 9
19 Runtime error 125 ms 262144 KB Execution killed with signal 9
20 Runtime error 124 ms 262144 KB Execution killed with signal 9
21 Runtime error 133 ms 262144 KB Execution killed with signal 9
22 Runtime error 144 ms 262144 KB Execution killed with signal 9
23 Runtime error 231 ms 262144 KB Execution killed with signal 9
24 Runtime error 153 ms 262144 KB Execution killed with signal 9
25 Runtime error 137 ms 262144 KB Execution killed with signal 9
26 Runtime error 131 ms 262144 KB Execution killed with signal 9
27 Runtime error 129 ms 262144 KB Execution killed with signal 9
28 Runtime error 128 ms 262144 KB Execution killed with signal 9
29 Runtime error 145 ms 262144 KB Execution killed with signal 9
30 Runtime error 147 ms 262144 KB Execution killed with signal 9
31 Runtime error 137 ms 262144 KB Execution killed with signal 9
32 Runtime error 146 ms 262144 KB Execution killed with signal 9
33 Runtime error 163 ms 262144 KB Execution killed with signal 9
34 Runtime error 135 ms 262144 KB Execution killed with signal 9
35 Runtime error 126 ms 262144 KB Execution killed with signal 9
36 Runtime error 137 ms 262144 KB Execution killed with signal 9
37 Runtime error 236 ms 262144 KB Execution killed with signal 9
38 Runtime error 130 ms 262144 KB Execution killed with signal 9
39 Runtime error 145 ms 262144 KB Execution killed with signal 9
40 Runtime error 135 ms 262144 KB Execution killed with signal 9
41 Runtime error 146 ms 262144 KB Execution killed with signal 9
42 Runtime error 132 ms 262144 KB Execution killed with signal 9