Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int NONE = 0;
- const int RED = 1;
- const int BLUE = 2;
- int n;
- int colors[5000] = {};
- int mat[5000][5000] = {};
- bool YES = true;
- void ds(int k, int type);
- int main(){
- cin >> n;
- char tmpc;
- for (int i = 1; i < n; i++)
- for (int j = i; j < n; j++){
- cin >> tmpc;
- if (tmpc == 'R')
- mat[i - 1][j] = RED;
- else
- mat[i - 1][j] = BLUE;
- }
- for (int i = 0; i < n; i++){
- ds(i, NONE);
- for (int j = 0; j < n; j++)
- colors[j] = NONE;
- }
- if (YES)
- cout << "YES" << endl;
- else
- cout << "NO" << endl;
- return 0;
- }
- void ds(int k, int type){
- if (colors[k] == NONE){
- colors[k] = type;
- }else{
- if (colors[k] != type && type != NONE){
- YES = false;
- return;
- }
- }
- for (int i = k + 1; i < n; i++){
- if (mat[k][i] == type || type == NONE)
- ds(i, mat[k][i]);
- if (!YES)
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement