Advertisement
Josif_tepe

Untitled

Apr 24th, 2022
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <set>
  4. #include <vector>
  5. #include <map>
  6. #include <fstream>
  7. #include <set>
  8. #include <cmath>
  9. using namespace std;
  10. int power(int x) {
  11.     int result = 1;
  12.     while(x > 0) {
  13.         result *= 3;
  14.         x--;
  15.     }
  16.     return result;
  17. }
  18. int main(){
  19.     int n, t;
  20.     cin >> n >> t;
  21.     vector<int> a(n), b(n), c(n);
  22.     for(int i = 0; i < t; i++) {
  23.         cin >> a[i] >> b[i] >> c[i];
  24.         b[i]--;
  25.         c[i]--;
  26.     }
  27.     long long result = 0;
  28.     for(int mask = 0; mask < power(n); mask++) {
  29.         string s = "";
  30.         int tmp = mask;
  31.         while(tmp > 0) {
  32.             s += (tmp % 3) + '0';
  33.             tmp /= 3;
  34.         }
  35.        
  36.         while(s.size() < n) {
  37.             s += "0";
  38.         }
  39.         reverse(s.begin(), s.end());
  40.         bool ok = true;
  41.         for(int j = 0; j < t; j++) {
  42.             set<int> st;
  43.             for(int x = b[j]; x <= c[j]; x++) {
  44.                 if(s[x] == '0') {
  45.                     st.insert(0);
  46.                 }
  47.                 if(s[x] == '1') {
  48.                     st.insert(1);
  49.                 }
  50.                 if(s[x] == '2') {
  51.                     st.insert(3);
  52.                 }
  53.             }
  54.             if(st.size() != a[j]) {
  55.                 ok = false;
  56.             }
  57.         }
  58.         if(ok) {
  59.             result++;
  60.         }
  61.     }
  62.     cout << result << endl;
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement