L2-4 彩虹瓶 (25分)
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<cstring> #include<string> #include<map> #include<queue> #include<iomanip> #include<stack> using namespace std; #define STDIN freopen("in.in", "r", stdin);freopen("out.out", "w", stdout); const int N = 1000 + 10; int a[N]; int main() { // STDIN int n, m, k; cin >> n >> m >> k; stack<int> st; while (k --) { int top = 1; int t; bool fl = true; while(st.size()) st.pop(); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n;) { t = a[i]; if (a[i] == top) { top++; i++;continue; } else { while (st.size() && st.top() == top){ top++; st.pop(); } if (a[i] == top) { top++; i++;continue; } if ((st.size() &&t < st.top() )|| st.empty()){ st.push(t); i++; if (st.size() > m) { fl = false; break; } } else { fl = false; break; } } } if (fl) puts("YES"); else puts("NO"); } }