Stanford ICPC

We are the Stanford International Collegiate Programming Contest (ICPC) club!

Come learn about algorithms and data structures, and apply your knowledge in fun competitions!

Join Us About ICPC

A global community

Over 50,000 students across 3,000 universities around the world participate in ICPC each year.

Solve problems while making friends

Participate individually or as a team! Level up your programming skills together with your teammates. We welcome students of all backgrounds and experiences.

Sample Problem


You are given two binary strings, with the same length and same number of ones. You may repeatedly spend one dollar to take either string and swap two of its adjacent digits. How much does it cost to make the two strings identical?

Sample Input

00101 11000

Sample Output


int main() {
  string s1, s2;
  vector<int> v1, v2;
  int cost = 0;
  cin >> s1 >> s2;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] == '1') v1.push_back(i);
    if (s2[i] == '1') v2.push_back(i);
  for (int i = 0; i < v1.size(); i++) {
    cost += abs(v1[i] - v2[i]);
  cout << "$" << cost << endl; 
  return 0;
s1, s2 = input().split(' ')
v1 = [i for i, digit in enumerate(s1) if digit == '1']
v2 = [i for i, digit in enumerate(s2) if digit == '1']
cost = sum(abs(v1[i] - v2[i]) for i in range(len(v1)))
print("$%u" % cost)