Skip to content

Instantly share code, notes, and snippets.

@zyouyowa
Last active July 7, 2017 05:46
Show Gist options
  • Save zyouyowa/3ffd5c727bc8ffb3e2ec4e6231392f73 to your computer and use it in GitHub Desktop.
Save zyouyowa/3ffd5c727bc8ffb3e2ec4e6231392f73 to your computer and use it in GitHub Desktop.
例のアレ
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]){
int a[] = {10, 13, 13, 15, 20, 25};
int b[] = {6, 6, 8, 8, 11, 13};
int n = 6, w = 21;
int i = n-1, j = 0;
int i2 = i, j2 = j;
int count = 0;
while(i >= 0 && j < n){
while(i2-1 >= 0 && a[i2-1] == a[i]) i2--;
while(j2+1 < n && b[j] == b[j2+1]) j2++;
int sum = a[i] + b[j];
if(sum > w){
i = --i2;
}
else if(sum < w){
j = ++j2;
}
else {
count += (i - i2 + 1) * (j2 - j + 1);
i = --i2;
j = ++j2;
}
}
cout << count << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment