Submission #1163712


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif
 
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}
 
template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

int N;
int a[MAX];
int b[MAX];

void solve() {
	cin >> N;
	rep(i, N) cin >> a[i] >> b[i];
	int cur = 0;
	rrep(i, N) {
		int v = (a[i] + cur) % b[i];
		if (v != 0) {
			cur += b[i] - v;
		}
		if (test) dump(cur);
	}
	cout << cur << endl;
}

signed main() {
	cout << fixed << setprecision(20);
	while(true) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Submission Info

Submission Time
Task A - Multiple Array
User naimonon77
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2052 Byte
Status AC
Exec Time 96 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 18
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 80 ms 1792 KB
02.txt AC 80 ms 1792 KB
03.txt AC 80 ms 1792 KB
04.txt AC 81 ms 1792 KB
05.txt AC 80 ms 1792 KB
06.txt AC 80 ms 1792 KB
07.txt AC 57 ms 1792 KB
08.txt AC 96 ms 1792 KB
09.txt AC 58 ms 1792 KB
10.txt AC 84 ms 1792 KB
11.txt AC 57 ms 1792 KB
12.txt AC 35 ms 1792 KB
13.txt AC 61 ms 1792 KB
14.txt AC 87 ms 1792 KB
15.txt AC 1 ms 256 KB
16.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB