algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

main.cpp (1137B)


      1 #include <iostream>
      2 #include <vector>
      3 
      4 std::string solve(std::vector<int>& nums, std::vector<int>& bools) {
      5     bool hasZero = 0;
      6     bool hasOne = 0;
      7 
      8     for(int i = 0; i < bools.size(); ++i) {
      9         if(bools[i] == 1) {
     10             hasOne = 1;
     11         } else {
     12             hasZero = 1;
     13         }
     14         if(hasZero && hasOne) {
     15             return "Yes";
     16         }
     17     }
     18 
     19     for(int i = 1; i < nums.size(); ++i) {
     20         if(nums[i] < nums[i-1]) {
     21             return "No";
     22         }
     23     }
     24 
     25     return "Yes";
     26 }
     27 
     28 int main() {
     29     int problemCount = 0;
     30     std::cin >> problemCount;
     31 
     32     for(int i = 0; i < problemCount; ++i) {
     33         std::vector<int> nums {};
     34         std::vector<int> bools {};
     35         int numberCount = 0;
     36         std::cin >> numberCount;
     37 
     38         for(int y = 0; y < numberCount; ++y) {
     39             int current = 0;
     40             std::cin >> current;
     41             nums.push_back(current);
     42         }
     43         for(int y = 0; y < numberCount; ++y) {
     44             int current = 0;
     45             std::cin >> current;
     46             bools.push_back(current);
     47         }
     48         std::cout << solve(nums,bools) << std::endl;
     49     }
     50 
     51 
     52 }