QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808552#85. Leverage MDTLaVuna47#AC ✓62ms5072kbC++172.2kb2024-12-10 21:27:552024-12-10 21:28:04

Judging History

你现在查看的是最新测评结果

  • [2024-12-10 21:28:04]
  • 评测
  • 测评结果:AC
  • 用时:62ms
  • 内存:5072kb
  • [2024-12-10 21:27:55]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


bool is_good(const vector<string>& a, int X)
{
	int n=sz(a),m=sz(a[0]);
	vector<vector<bool>> b(n, vector<bool>(m,false));
	FOR(i,0,n)
	{
		int cg=0;		
		FOR(j,0,X)if(a[i][j]=='G')++cg;
		if(cg==0||cg==X) b[i][0]=1;
		FOR(j,X,m)
		{
			if(a[i][j]=='G')++cg;
			if(a[i][j-X]=='G')--cg;
			if(cg==0 || cg==X) b[i][j-X+1]=1;
		}
	}
	FOR(i,0,m-X+1)
	{
		int o=0;
		FOR(j,0,X)if(b[j][i])++o;
		if(o==X)return true;
		FOR(j,X,n)
		{
			if(b[j][i])++o;
			if(b[j-X][i])--o;
			if(o==X)return true;
		}
	}
	return false;
}

int solve()
{
	int n,m;
	if(!(cin>>n>>m))
		return 1;
	vector<string> a(n);
	FOR(i,0,n)cin>>a[i];
	
	int l = 1, r = min(n,m);
	while(r-l>1)
	{
		int mid=(l+r)/2;
		if(is_good(a, mid))
			l=mid;
		else
			r=mid;
	}
	if(is_good(a,r))
		l=r;
	cout<<l*l<<'\n';
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

2 2
GG
GG

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

1 1
B

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

2 2
BB
BB

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

2 2
GB
BB

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

2 2
BG
BB

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

2 2
BB
GB

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

2 2
BB
BG

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2 2
BB
GG

output:

4

result:

ok single line: '4'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 2
BG
BG

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2 2
BG
BG

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

2 2
GG
GG

output:

4

result:

ok single line: '4'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

5 5
GGGGG
GBBBG
GBBBG
GBBBG
GGGGG

output:

9

result:

ok single line: '9'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5 1
G
G
G
G
G

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

5 1
G
B
G
G
G

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1 5
GGGGG

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

1 5
GBGGG

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

10 10
GBBBBGBBGB
GBBBGGBBGB
BGBGBBGGBB
BGBGBBBGBG
BGBBGGBGBG
GGBGBBBGGG
BBGGBGBBBB
GGGGBGGGGG
GBBBBGBBGB
BGBBGGGGBB

output:

9

result:

ok single line: '9'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

10 10
GGBBGBGBGB
BGGBGGBGGB
BGGGBGBGGG
GGGBGBGGBB
BBBBBGBBGB
BGBBBGGGGB
BGBBGBGGGG
GBBGGGBBBB
GGBGBGBGGB
BBBBGBGBGG

output:

9

result:

ok single line: '9'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

30 30
BBGBGBGGGGGBBGBBGBGBBGGGGBBGGG
BBBBBBGBGGBGBGBBGBGGBBGBBBGBBG
BGBBBGGGGBGGBBGBGGGBBBBGGGGBBB
BBGBBGGBBBBBGGGGGBBBGBGGBGGBGG
BGBBBGGGGBBGGBBGBBGGBGGGBGGGGB
GGBBGGBGBBBGBBBGBGGBGBGBGGGBGG
BBGBBGGGBGGBGBBBBGBGBGGBBBGGBG
GGGGBGGBGGBGGGGGGBBGBBGGGBGGBG
BBBBGGBGGGGBBBGBGBBBBBGGGGGBBG
BGGGGBGBGBGBGBB...

output:

9

result:

ok single line: '9'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

30 30
GGBGGGGGBGGBGGBGBGBGGBGGGGGBBB
BGGGBBBBBBBGBBGGGBBGGGBBGGBBGB
BGBGBBBGBGBBGBGBBGBGGBGGBBGBGG
BBBGGBGGGGGBGGBBBBBGBGBGBBGBGG
GGBGGGBBGBGGGGBGGBGBGGBGGBGBGG
BBGGBBGGBGGGGBGBBBBBBBGBGGBGBB
BGBGGBBGBBGBGBGBGBGBGGGGBGGBGB
GGBBBBGGBBGGBGGGGBBGGBBBGBBGGB
GGBGGBGBBBBBBBGGBGBGBBGBBBBBBG
GGBBBBGGGBGGBGB...

output:

9

result:

ok single line: '9'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

100 100
GGGBGBGGGGBBBGGGBGBGBBGGBBBBBGGGGGBGBBBGBGGGGBGBBBGBBGGGGBBBGGGGGBBGGBGBGGGBBBBGBBGGBBGBBGGBGGGBBBBG
BGGGBBBGGGBGGGGGBBBGBBBBGGGGGBGGBBBBBBGGGGBBBBBGGBBGBBBGGBBBBBBGBGBGBBBBGBBBGBGBGBBGBGBBGBGGBGGBGBBG
GBBBGGGBGBGGGGBBBGBBGGGGBGBBGBGGBBGBBBGBBBGGBGGGBBGBBBGBGGGBGGBGBGBBBBBGGGBGGGGBGBGBGBBBGB...

output:

16

result:

ok single line: '16'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

100 100
GGGGBGGGBGGGBGGBBGGGGGGBGBBGGBBGBBGGGGGGBBBGGGGBBBBBGBGGGBGBGGBGBBBGBBBBBBBBGGBGBGBGBGGGBGGGBGGGBGGG
BGGGGGGBBGGBGGBGBBGGBBGGBGGBGBGBBGGBBBGBBGGGBBBGBBGBGGGGBBGBGGBBBGGGBBGGBGGGBBBGGBBBGBGBGGGBBBBBBBGB
BGBBGGBBBBGBGGBGBGGBGGBGBBGBBBGBGGBBGBBGGBBGBBBGGGBBGGBGBGGGBGGBGGGGBBBBBBGGBGGGGBBBGGGGBG...

output:

16

result:

ok single line: '16'

Test #23:

score: 0
Accepted
time: 11ms
memory: 5072kb

input:

1000 1000
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...

output:

1000000

result:

ok single line: '1000000'

Test #24:

score: 0
Accepted
time: 5ms
memory: 3664kb

input:

300 300
BGBBBBBBGGGBGBGBGBGGGBGGGGBGGBBBBBBBGBBGGBGGBGGBBGBBGGGBGBGBGGGGGBBBGGBBGGBBBGGGBBBBGBBBBGGBBGBBGBGBBGBGGGGGBGBBGBGGBBBGGGBBGGBBBBBGBGGGGGGBBBGGGGBGBBBBBGGBBBBGGBGBBGGGGBGGGGBBGGBGGBGGGGGBBGGBBGGBGBBGBBBBBBGGGBBGBGBGBGBBGGGBBGGGBBGBGGBGGBBBGGGGGGGGGBGBGBBBGBGBGBGGBGBGGBBGBBBGGBGGBBBGBGBGBBBB...

output:

16

result:

ok single line: '16'

Test #25:

score: 0
Accepted
time: 5ms
memory: 3668kb

input:

300 300
BBBBBGGGBGGBGGBBGBBBGGGGGBGBBGGGBGGBGGBBBGBGGGGBBGGBBBBGBBBGGBGGBGGGGBBGBBGGBGGGBGGGBGGBBGBBGGGGBBGBBGBBBBBBGBBBBBBGGGBBGGGBGBGGBBBBBBGGGGBGGGBGGGBBGGBGBGBGGGBBGGGBBBBGGBBBGBGBBBGBGBBBBGGBGGGGGBBBBGGGGGGGGGGBBBGBBBGBBGGGGBBBBBGBBGGBBBGBBBGGGGGBBGBGGBGBGGBGGGBBGGBGBGGGGGBGGBBBGBBGGBGBBGBGBBGG...

output:

16

result:

ok single line: '16'

Test #26:

score: 0
Accepted
time: 14ms
memory: 3944kb

input:

500 500
GBGBBGGBBGGBGGGGGBGGBGBBBGGBBBGBGGBBGBGGBBGBGGBBGGGGBBBBBGGGBBBBBBBGGGGGGBGGBGGGGBGBBGGGGBBGGGGBBGGGGBGGBGGGBGGGBBBBBBGBBBGGBGGGGBBBGGGBBBBBBBBGGGBGBBGBGGGGGBGGGBGGGBGBGBBGGBGBBBGGBBGGGGGBBGBBGBBGBGGBBBGBGGGBBGBGGBBBGGBGGBGGGBBGBBBBGGBBGBGBBGGGBBBGBBGGBBBGGBBBBGGGBBBBBGBBGBGGGBBGBGBGBGGBGBGG...

output:

25

result:

ok single line: '25'

Test #27:

score: 0
Accepted
time: 14ms
memory: 3944kb

input:

500 500
BBGBBGBGGBGGGGGBBBGBBBBBGGBGBBBGBGBBBGGBBBBBGBGBBBBGBGBGBGGGBBGGBGGGGBBGBBGBBBBGBBGBGGBGGBBBBBGBBBBGGGGBGGGGBGGBGGGBGGGGBGBBBBBGGBBBBBBGBBBGGGBBGBBGGBGGBGGBGBGBBGGBGGGGGGBBGGGBGBBBBGGGGBBBGBGBBGBGBBBGGBGGGBGGBBGGBGBGBGBGBBGBGGGGGGGGBGGGBBBGGGGGBBBGGGGGGGBBGGBGGBBBBGGGBGGBBBGBBBBGBBBBGGGGGGGB...

output:

16

result:

ok single line: '16'

Test #28:

score: 0
Accepted
time: 62ms
memory: 4872kb

input:

1000 1000
GBGBBBGBBGBGBBGBBBGBGBGBGBGGGGBBGBBGBGBGBBGGGBGGBBBGBGBGBBGBGBBGGBGBGGBBGGGGGGGBGBGGGBBBGGBBBGGGBGBGGBGBBBBGBGBGGGGBGGBBBGGGGBGGBGBGGGGBGBGGGBGBBBBBGGGGBBGGGGBBBGBGBBGBBBGBBBGGBGGBGGGGGBGBGBBBBGBBBGBGBGBGBBBGGBBGGGGGBGBBGBBBGGGGGBBBGBBBBGGBGBGGGBGGGBBBGGGGBBGBGBBBBGGGGGBBGBGBBBBGGGGBBBGGGB...

output:

16

result:

ok single line: '16'

Test #29:

score: 0
Accepted
time: 57ms
memory: 4912kb

input:

1000 1000
GGBBGGBBGBBGGGBBGGGBGBBGGBGBBBBBBBBGGGGBGGBBGBGBBGGBGBGGBBGBBGBBBBGBBBBGBBBBGGGBBGGBBBBBGBGGGGBGBGGBGGGGBGGGGBBGGBGBBGGBGBGBGGBBBBGGBBGBBBBBGBBGBBBGBGGGBBBGGBBBBBGGBBGGBGBBBGBGGGBBBBGBBBBGGBBGGBGBBBGBBBGGBGGGGGBBGGGGBBGBBGGGBBGBGBGGBBGGGGGGBGBBGBGBBBBGGGBBBGBBGBGGGGGGGBGBBGGGBGBGGGGGBGGGGB...

output:

25

result:

ok single line: '25'

Test #30:

score: 0
Accepted
time: 7ms
memory: 4868kb

input:

1000 1000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

1000000

result:

ok single line: '1000000'

Test #31:

score: 0
Accepted
time: 10ms
memory: 4868kb

input:

1000 1000
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...

output:

998001

result:

ok single line: '998001'

Test #32:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3 3
BBB
BGB
BBB

output:

1

result:

ok single line: '1'

Test #33:

score: 0
Accepted
time: 0ms
memory: 3948kb

input:

300 300
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...

output:

90000

result:

ok single line: '90000'

Test #34:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

300 300
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

90000

result:

ok single line: '90000'

Test #35:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 1
G

output:

1

result:

ok single line: '1'