Help I gained 30 points that round
I should be purple..
the color blue is bringing me PTSD..
plz fix QwQ
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Help I gained 30 points that round
I should be purple..
the color blue is bringing me PTSD..
plz fix QwQ
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int ll = 1, rr = 1000000;
int ans;
while (ll <= rr) {
int mid = (ll + rr) / 2;
cout << mid;
fflush(stdout);
string s;
cin >> s;
if (s == ">=") {
ans = mid;
ll = mid + 1;
}
else {
rr = mid - 1;
}
}
cout << "! " << ans;
fflush(stdout);
return 0;
}
This is an easy interactive question that guesses the number 1 to 1000000 by binary search. However, I am new to the concept of interactive problems, and I am getting an idleness TLE on this problem. Can someone tell me what is causing the Idleness on my code? Thanks in advance.
Problem statement : https://codeforces.me/gym/101021/problem/1
Problem : https://atcoder.jp/contests/abc171/tasks/abc171_f
Ill explain my idea below with the first example.
_______ o ___________ o ________ f __________
we are able to place letters in the 4 slots here.
Lets say that we place a letters on the first slot, b letters on the second, c letters on the third, and d letters on the fourth slot. therefore, a+b+c+d = n.
The first slot is free to place slot -> we have 26^a ways to put it.
The second slot, third slot, fourth slots have a restriction; you cannot place the letter that is at the left of the slot. (you can't place o in the second, third slot, you can't place f in the fourth slot) -> by this restriction, we can prevent duplicates being counted. -> ex) ooaoaaof -> this will be only counted one time. -> therefore, there's 25^(b+c+d) = 25^(n-a) ways to put in the slots.
if a is 0, b+c+d = n. the ways to distribute numbers to b, c, d is H(3,n)=C(3+n-1, n).
if a is 1, b+c+d = n-1. the ways to distribute numbers to b, c, d is H(3,n-1)=C(3+n-1-1, n-1)
...
if a is n, b+c+d = 0 the ways to distribute numbers to b, c, d is H(3,0)=C(3+0-1, 0).
-- therefore the total = sigma k=0 to n (26^k * 25^n-k * H(len(S),n-k))
there was my logic, and I coded it but it came with a result of only 70 out of 100.
Can someone help me finding the counterexample?
Code below:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#define ff first
#define ss second
#define MOD 1000000007LL
using namespace std;
using pii = pair<int, int>;
using ll = long long;
vector<ll> f(3000000);
tuple<ll, ll, ll> exgcd(ll a, ll b) {
if (b == 0)
return make_tuple(a, 1, 0);
ll g, x, y;
tie(g, x, y) = exgcd(b, a % b);
return make_tuple(g, y, x - (a / b) * y);
}
ll moddiv(ll a, ll b)
{
ll bb;
tie(ignore, bb, ignore) = exgcd(b, MOD);
if (bb < 0) b += MOD;
return (a * bb) % MOD;
}
ll getC(int a, int b)
{
if (a < b) return 0;
return moddiv(moddiv(f[a], f[a - b]), f[b]);
}
ll getH(int a, int b)
{
return getC(a + b - 1, b);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
f[0] = 1;
for (int i = 1; i < f.size(); i++) f[i] = (f[i - 1] * i) % MOD;
int k;
cin >> k;
string s;
cin >> s;
ll answer = 0;
vector<ll> p26(k + 1), p25(k + 1);
p26[0] = p25[0] = 1;
for (int i = 1; i <= k; i++) {
p26[i] = (p26[i - 1] * 26) % MOD;
p25[i] = (p25[i - 1] * 25) % MOD;
}
for (int i = 0; i <= k; i++) {
ll tmp = (p26[i] * getH(s.length(), k - i)) % MOD;
tmp = (tmp * p25[k - i]) % MOD;
answer = (answer + tmp) % MOD;
}
cout << answer;
return 0;
}
https://codeforces.me/contest/1335/problem/E1
When I run the test, it keeps going well, and suddenly it fails on test 10 data 596 or something, so I cannot see what test case is causing the problem. Im asking for help after 3+hours of coding ! Id really appreciate any help.
It works on almost all cases, but there seems to be a counterexample that I seem to be missing. Thanks :)
#include <iostream>
#include <vector>
using namespace std;
int min_num(int a, int b)
{
return a<b ? a : b;
}
void solve()
{
int n;
int a[200002];
vector<int> cnt[202];
int ccnt[200002]={0,};
cin >>n;
int i,j,k;
for(i=1 ; i<=n ; i++)
{
cin >>a[i];
cnt[a[i]].push_back(i);
//this cnt stores the location of each number
//ex) 1 1 3 3 2 1 -> cnt[1] = 1, 2, 6 cnt[2] = 5, cnt[3] = 3, 4
ccnt[a[i]]++;
}
int cntmax = 0;
for(i=1 ; i<=200000 ; i++) if(cntmax < ccnt[i]) cntmax = ccnt[i];
// this for loop is for a palindrome that uses only 1 kind of number, so the number
// with the most count is the longest palindrome
// realmax is where the final answer will be stored
int realmax=cntmax;
for(i=1 ; i<=200 ; i++) // middle part of palindrome
{
for(j=1 ; j<=200 ; j++) // left/right part of palindrome
// I am searching for the longest palindrome which uses i as the left/right part
// and j as the middle part such like i i i j j j j i i i
{
int max = 0;
if(i!=j && cnt[i].size() > 0 && cnt[j].size() > 0)
{
vector<int> b;
int l=0;
for(k=0; k<cnt[i].size() ; k++)
{
while(1)
{
if(l==cnt[j].size()) break;
if(cnt[j][l] < cnt[i][k])
{
l++;
}
else break;
}
b.push_back(l);
}
//b stores the number of cnt[j] members that is less than each cnt[i] members
//if cnt[i] = 1 2 7 8, cnt[j] = 3, 5
// b will be 0, 0, 2, 2 (b[i] = count of cnt[j] members that is less than cnt[i][k]
for(k=0 ; k<b.size() ; k++)
{
int sum=0;
int frontback = min_num(b[k], cnt[j].size()-b[k]);
sum += frontback * 2;
//frontback is the length of the surrounding two pallindromes
int t;
int count = 0;
// now we calculate the length of the middle part of the palindrome
// if cnt[j].size — b[t] is more than the frontback, we can extend the middle part
for(t=k ; t<b.size() ; t++)
{
if(cnt[j].size() - b[t] >= frontback) count++;
else break;
}
sum+=count;
if(max < sum) max=sum;
}
}
if(realmax < max) realmax = max;
}
}
cout << realmax << "\n";
return;
}
int main(void)
{
int n;
cin >> n;
while(n--)
{
solve();
}
return 0;
}
Name |
---|