Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef enum {
- OK,
- RISOLTO,
- IMPOSSIBILE
- } stato_t;
- typedef struct {
- int domino1;
- int domino2;
- } coppia_t;
- stato_t correggi(int N, int altezze[], coppia_t* scambio) {
- int okTo = 0;
- bool ok = 1;
- vector<int> notKnocked;
- for(int i = 0; i < N; i++) {
- if(okTo<i) {
- ok = 0;
- notKnocked.push_back(i);
- }
- okTo = max(okTo, i+altezze[i]-1);
- }
- if(ok)
- return OK;
- int l = notKnocked[0];
- int r = notKnocked.back();
- if(N>100000) {
- return IMPOSSIBILE;
- }
- for(int x = 0; x < N; x++) {
- for(int y = max(0,r-altezze[x]+1); y < l; y++) {
- swap(altezze[x], altezze[y]);
- int okTo = 0;
- bool ok = 1;
- for(int i = 0; i < N; i++) {
- if(okTo<i)
- ok = 0;
- okTo = max(okTo, i+altezze[i]-1);
- }
- if(ok) {
- scambio->domino1 = x;
- scambio->domino2 = y;
- return RISOLTO;
- }
- swap(altezze[x], altezze[y]);
- }
- }
- return IMPOSSIBILE;
- }
Add Comment
Please, Sign In to add comment