AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC091-D Two Sequences
C++のソース
#pragma GCC target("avx2")
#pragma GCC optimize ("-O3", "unroll-loops")
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
std::vector<std::string> GetInputValues();
std::string InputPattern = "InputX";
std::vector<std::string> GetInputValues()
{
std::vector<std::string> InputValuesVect;
if (InputPattern == "Input1") {
InputValuesVect.push_back("2");
InputValuesVect.push_back("1 2");
InputValuesVect.push_back("3 4");
}
else { //実際の入力
while (true) {
std::string wkStr;
std::getline(std::cin,wkStr);
if(std::cin.eof()) break;
InputValuesVect.push_back(wkStr.c_str());
}
}
return InputValuesVect;
}
unsigned ArrA[200001];
unsigned ArrB[200001];
int main()
{
std::vector<std::string> InputVect = GetInputValues();
std::vector<unsigned> VectA;
std::istringstream iss1(InputVect.at(1));
while(iss1.eof() == false){
unsigned wkInt;
iss1 >> wkInt;
VectA.push_back(wkInt);
}
std::vector<unsigned> VectB;
std::istringstream iss2(InputVect.at(2));
while(iss2.eof() == false){
unsigned wkInt;
iss2 >> wkInt;
VectB.push_back(wkInt);
}
for(unsigned I=0;I<=(unsigned)VectA.size()-1;I++){
ArrA[I] = VectA[I];
}
for(unsigned I=0;I<=(unsigned)VectB.size()-1;I++){
ArrB[I] = VectB[I];
}
unsigned UB_A=(unsigned)VectA.size()-1;
unsigned UB_B=(unsigned)VectB.size()-1;
unsigned Answer = 0;
for(unsigned I=0;I<=UB_A;I++){
for(unsigned J=0;J<=UB_B;J++){
unsigned Wa=ArrA[I]+ArrB[J];
Answer ^= Wa;
}
}
printf("%d\n",Answer);
}
解説
ナイーブ解を、SIMDを使って通してます。