-
Notifications
You must be signed in to change notification settings - Fork 0
/
matriz_escada.cpp
executable file
·148 lines (124 loc) · 3.24 KB
/
matriz_escada.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// https://www.beecrowd.com.br/judge/pt/problems/view/2450
#include <bits/stdc++.h>
#define vll vector <long long int>
#define lli long long int
#define ulli unsigned long long int
#define vbool vector <bool>
#define LOOP(I, S, E) for(lli I = S; I < E; I++)
#define LOOPIN(i, E, V) for(lli i = 0; i < E; i++){cin >> V[i];}
#define LOOPOUT(i, E, V) for(lli i = 0; i < E; i++){cout << V[i] << endl;}
#define SWAP(A, B) A ^= B ^= A ^= B
#define TOBIN(I, b) bitset<b>(I).to_string()
#define endl '\n'
#define sws ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
using namespace std;
ulli nop(ulli number);
ulli hibit(ulli x);
bool isPalindrome(string s);
bool validBracket(string b);
lli sumdigits(lli x);
lli N, M;
unsigned int matriz[500][500];
bool verificaEscada(lli x, lli y){
// Verificar se é o elemento mais a esquerda.
bool maisAesquerda = true;
LOOP(i, 0, y){
if(matriz[x][i] != 0){
maisAesquerda = false;
break;
}
}
if(maisAesquerda){
LOOP(i, x+1, N){ // linhas abaixo de x
LOOP(j, 0, y+1){ // colunas antes de x;
if(matriz[i][j] != 0) return false;
}
}
}
return true;
}
/*====================================================================================================*/
int main(void){
sws
cin >> N >> M;
bool escada = true;
LOOP(i, 0, N){
LOOP(j, 0, M){
cin >> matriz[i][j];
}
}
lli zeros;
bool temquezerar;
LOOP(i, 0, N){
zeros = 0;
LOOP(j, 0, M){
if(matriz[i][j] != 0){
if(!verificaEscada(i, j)){
// cout << "N" << i << " " << j << endl;
cout << "N" << endl;
return 0;
}
}
else{
zeros++;
}
}
if(zeros == M-1) temquezerar = true;
if((temquezerar) && (zeros < M-1)){
cout << "N" << endl;
return 0;
}
}
cout << "S" << endl;
return 0;
}
/*====================================================================================================*/
// Function to return the ~X.
ulli nop(ulli number){
return (~number)^(ULLONG_MAX<<(hibit(number)));
}
// Function to return the highest bit position of a number.
ulli hibit(ulli x){
return (lli)log2(x)+1;
}
// Function to verify if a given string is a palindrome or not.
bool isPalindrome(string s){
string aux = s;
reverse(aux.begin(), aux.end());
LOOP(i, 0, s.size()){
if(aux[i] != s[i]){
return false;
}
}
return true;
}
// Function to verify if a string with brackets is valid or not.
bool validBracket(string b){
stack <char> verify;
LOOP(i, 0, b.size()){
if(b[i] == ')' && verify.top() == '('){
verify.pop();
}
else{
verify.push(b[i]);
}
}
if(!verify.empty()){
return false;
}
else{
return true;
}
}
// Function to return the sum of digits of a number.
lli sumdigits(lli x){
lli rest;
lli result = 0;
do{
rest = x % 10;
result += rest;
x = x/10;
}while(x > 0);
return result;
}
// Accepted.