Submission #889902

# Submission time Handle Problem Language Result Execution time Memory
889902 2023-12-20T09:27:09 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 262144 KB
#include <bits/stdc++.h>
#define ll long long
#define fort(x , y) for(int y = 1 ; y <= x ; y++)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define int long long
#define F first
#define S second
using namespace std;
const int N = 1e6 + 5;
const int NN = 1e9 + 7;
int n,m,w[N],l,r,k,p[N],b[N],used[N];
vector <int> g[N];
void dfs(int v){
	used[v] = 1;
	for(auto to : g[v]){
		if(used[to] == 0){
			dfs(to);
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i++){
		cin >> w[i];
		p[i] = p[i - 1] + w[i];
		b[i] = w[i];
	}
	//sort(b + 1 , b + n + 1);
	for(int j = 1 ; j <= m ; j++){
		vector <int> ans;
		ans.clear();
		cin >> l >> r >> k;
		if(l == r){
			if(w[l] <= k){
				cout << 1 << '\n';
			}
			else{
				cout << 0 << '\n';
			}
			continue;
		}
		sort(b + l , b + r + 1);
		for(int i = l ; i <= r ; i++){
			if(w[i] != b[i]){
				ans.pb(i);
			}
		}
		for(int i = l ; i <= r ; i++){
			for(int u = i + 1 ; u <= r ; u++){
				if(w[i] + w[u] <= k){
					g[i].pb(u);
					g[u].pb(i);
				}
			}
		}
		dfs(ans[0]);
		bool oknt = 0;
		for(int i = 0 ; i < ans.size() ; i++){
			if(used[ans[i]] == 0){
				oknt = 1;
				break;
			}
			//cout << ans[i] << ' ';
		}
		if(oknt){
			cout << 0 << '\n';
		}
		else{
			cout << 1 << '\n';
		}
		for(int i = l ; i <= r ; i++){
			used[i] = 0;
		}
	}

}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:62:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int i = 0 ; i < ans.size() ; i++){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 6 ms 29328 KB Output is correct
3 Incorrect 40 ms 35920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 6 ms 29328 KB Output is correct
3 Incorrect 40 ms 35920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3047 ms 58608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 290 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 6 ms 29328 KB Output is correct
3 Incorrect 40 ms 35920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29276 KB Output is correct
2 Correct 6 ms 29328 KB Output is correct
3 Incorrect 40 ms 35920 KB Output isn't correct
4 Halted 0 ms 0 KB -