Skip to content

Instantly share code, notes, and snippets.

#include <map>
#include <set>
using namespace std;
class GeometricProgressions {
public:
// decompose(120, &result) -> result will be {2:3, 3:1, 5:1}, meaning 2**3 * 3**1 * 5**1.
void decompose(int n, map<int, int>* result) {
// sqrt(500000000) < 22361
#include <hash_map>
int solve(const vector<int>& A,
const vector<int>& B,
const vector<int>& C,
const vector<int>& D) {
int count = 0;
hash_map<int, int> AB = create_pairs(A, B);
hash_map<int, int> CD = create_pairs(C, D);
for (const auto& pair : AB) {
@pascaljp
pascaljp / atcoder_abc755.cc
Created December 2, 2018 15:45
AtCoder ABC 755
#include <iostream>
using namespace std;
int generate_and_count(long long current, long long target, bool has3, bool has5, bool has7) {
int answer = 0;
if (current > target) {
return answer;
}
if (has3 && has5 && has7) {
answer++;
class Solution {
public:
int myAtoi(string str) {
int pos = 0;
while (str[pos] == ' ' && str[pos] != NULL) {
pos++;
}
if (str[pos] == NULL) {
return 0;
}
class Solution {
public:
int search(vector<int>& nums, int target) {
return nums.empty() ? -1 : find(nums, target, 0, nums.size() - 1);
}
int find(const vector<int>& nums, int target, int start, int end) {
// cout << start << " " << end << endl;
if (start == end) {
return nums[start] == target ? start : -1;
class Solution {
public:
int numIslands(vector<vector<char>>& grid) {
if (grid.empty() || grid[0].empty()) {
return 0;
}
vector<vector<bool>> checked(grid.size(), vector<bool>(grid[0].size()));
int islands = 0;
for (int y = 0; y < grid.size(); y++) {
for (int x = 0; x < grid[0].size(); x++) {
@pascaljp
pascaljp / youtube_data_api_sample.ts
Last active July 11, 2023 20:30
Youtube Data APIを用い、アカウント名'GoogleDevelopers'の最新の動画の最新のコメントを取ってくるサンプルプログラム
// Reference: https://developers.google.com/youtube/v3/quickstart/nodejs?hl=ja
// This program loads client secrets from a local file (~/.credentials/youtube-nodejs-quickstart.json).
// To set up the client secret,
// 1. visit https://console.cloud.google.com/.
// 2. Enable YouTube API.
// 3. Create an OAuth 2.0 client ID for a "Desktop Application".
// 4. Download the client secret file as a JSON file.
const fs = require('fs');
@pascaljp
pascaljp / youtube_data_api_livestream_sample.ts
Created July 11, 2023 21:41
Youtube Data APIを用い、ライブストリームのコメントを取ってくるサンプルプログラム
// Reference: https://developers.google.com/youtube/v3/quickstart/nodejs?hl=ja
// This program loads client secrets from a local file (~/.credentials/youtube-nodejs-quickstart.json).
// To set up the client secret,
// 1. visit https://console.cloud.google.com/.
// 2. Enable YouTube API.
// 3. Create an OAuth 2.0 client ID for a "Desktop Application".
// 4. Download the client secret file as a JSON file.
const fs = require('fs');