Submission #1351482

#TimeUsernameProblemLanguageResultExecution timeMemory
1351482cholpon1Superpiece (EGOI22_superpiece)C++20
42 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	vector <vector <int>> a(9, vector <int> (9));
	
	int q;
	cin >> q;
	while (q--) {
	    int a, b, c, d;
	    string s;
	    cin >> s;
	    cin >> a >> b >> c >> d;
	    bool gd = false, gdd = false;
	    for (int i = 0; i < s.size(); i++) {
	        if (s[i] == 'Q') gd = true;
	        if (s[i] == 'N') gdd = true;
	    }
	    if (s == "B") {
	        int mn = abs(min({a, b, c, d}));
    	    a += mn + 1;
    	    b += mn + 1;
    	    c += mn + 1;
    	    d += mn + 1;
	        if ((a % 2 != 0 && b % 2 != 0) || (a % 2 == 0 && b % 2 == 0)) {
    	        if ((c % 2 != 0 && d % 2 != 0) || (c % 2 == 0 && d % 2 == 0)) {
    	            if (abs(a-c) == abs(b-d)) {
    	                cout << "1\n";
    	            } else {
    	                cout << "2\n";
    	            }
    	            
    	        } else {
    	            cout << "-1\n";
    	        }
    	    } else {
    	        if ((c % 2 != 0 && d % 2 == 0) || (c % 2 == 0 && d % 2 != 0)) {
    	            if (abs(a-c) == abs(b-d)) {
    	                cout << "1\n";
    	            } else {
    	                cout << "2\n";
    	            }
    	            
    	        } else {
    	            cout << "-1\n";
    	        } 
    	        
    	    }
	    } else if (s == "P") {
	        if (b == d &&  c >= a) {
	            cout << abs(a - c) << "\n";
	        } else {
	            cout << "-1\n";
	        }
	    } else if (s == "KP" || s == "K" || s == "PK") {
	        cout << max(abs(a - c), abs(b - d)) << "\n";
	    } else if (gd && gdd) {
	        if (a == c || b == d || abs(a - c) == abs(b - d)) {
                cout << 1 << "\n";
            } else if (((abs(a-c) == 1 && abs(b-d) == 2) || (abs(a-c) == 2 && abs(b-d) == 1))) {
                cout << "1\n";
                
            } else {
                cout << 2 << "\n";
            }
	    } else  if (gd) {
	        if (a == c || b == d || abs(a - c) == abs(b - d)) {
                cout << 1 << "\n";
            } else {
                cout << 2 << "\n";
            }
	    }
	    
	    
	}
 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...