top of page

CCC '17 S3 - Nailed It! c++

#include <iostream> #include <string> #include <map> #include <set> #include <map> using namespace std; int main(){ int n; cin >> n; int wood_lens[2001] = {0}; int fences_lens[4001] = {0}; //set<int> woods; for (int x=0; x<n; x++){ int num; cin >> num; wood_lens[num]++; // woods.insert(num); } int greatest_number_of_appearences = 0; int answer = 0; //4 //1 2 3 4 // for(int i = 0; i < 2000; i++){ for(int j = i; j < 2001; j++){ if(wood_lens[i]!= 0 && wood_lens[j] != 0){ if(i == j){ fences_lens[i+j] += wood_lens[j]/2; } else{ fences_lens[i+j] += min(wood_lens[i], wood_lens[j]); } } } } for(int i = 0; i < 4001; i++){ if(greatest_number_of_appearences < fences_lens[i]){ greatest_number_of_appearences = fences_lens[i]; answer = 1; } else if (greatest_number_of_appearences == fences_lens[i]){ answer++; } } /*for(int i = 0; i < 4001; i++){ if(greatest_number_of_appearences == fences_lens[i]){ answer++; } }*/ /*int greatest_sum_numofboards; map<int,int> sum_to_sumcount_map; for (int x=0; x<n; x++){ for (int y=x+1; y<n; y++){ int sum = wood_lens[x] + wood_lens[y]; if (sum_to_sumcount_map.find(sum) == sum_to_sumcount_map.end()){ sum_to_sumcount_map[sum] = 1; } else{ sum_to_sumcount_map[sum]++; } if (sum_to_sumcount_map[sum] > greatest_number_of_appearences){ greatest_number_of_appearences = sum_to_sumcount_map[sum]; answer = 1; } else if (sum_to_sumcount_map[sum] == greatest_number_of_appearences){ answer++; } } }*/ cout << greatest_number_of_appearences << " " << answer; }

Recent Posts

See All

コメント


bottom of page