题目传送门
B. Koala and Lights
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.

After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters ai and bi. Light with parameters ai and bi will toggle (on to off, or off to on) every ai seconds starting from the bi-th second. In other words, it will toggle at the moments bi, bi+ai, bi+2⋅ai and so on.

You know for each light whether it’s initially on or off and its corresponding parameters ai and bi. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.

Here is a graphic for the first example.
Input
The first line contains a single integer n (1≤n≤100), the number of lights.

The next line contains a string s of n characters. The i-th character is “1”, if the i-th lamp is initially on. Otherwise, i-th character is “0”.

The i-th of the following n lines contains two integers ai and bi (1≤ai,bi≤5) — the parameters of the i-th light.

Output
Print a single integer — the maximum number of lights that will ever be on at the same time.

Examples
inputCopy
3
101
3 3
3 2
3 1
outputCopy
2
inputCopy
4
1111
3 4
5 2
3 1
3 2
outputCopy
4
inputCopy
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
outputCopy
6
Note
For first example, the lamps’ states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).

In the second example, all lights are initially on. So the answer is 4.

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define ll long long
#define p 99824433
const int N=1e2+15;
int a[N],b[N];
char s[N];
ll ww(ll a,ll b)
{
    ll ans = 0;
    while (b)
    {
        if (b & 1)
        {
            ans = (ans + a)%p;
        }
        a = (a + a)%p;
        b >>= 1;
    }
    return ans;
}
char vis(char a)
{
    if(a=='0')
        return '1';
    return '0';
}
ll yy(ll a, ll b)
{
    ll ans=1;
    while(b)
    {
        if(b & 1) ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    cin>>s;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
    }
    int t;
    int ans=0;
    int sum=0;
    int ss=0;
    for(int j=1; j<n*1010; j++)
    {
        t=0;
        for(int i=0; i<n; i++)
        {
            if(!ss)if(s[i]=='1')sum++;
            if(j>=b[i]&&!((j-b[i])%a[i]))
                s[i]=vis(s[i]);
            if(s[i]=='1')t++;
        }
        ss=1;
        ans=max(t,ans);
    }
    cout<<max(ans,sum);
    return 0;
}