QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140358#6568. Space Alignmentsmosp#WA 1ms3484kbC++203.7kb2023-08-15 19:36:392023-08-15 19:36:39

Judging History

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

  • [2023-08-15 19:36:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3484kb
  • [2023-08-15 19:36:39]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;
typedef long long ll;


ll n;
vector<ll> indents;
vector<ll> spaces;
vector<ll> tabs;

ll solve(ll eq1, ll eq2, ll &spt, ll &spi){
    ll t1 = tabs[eq1];
    ll t2 = tabs[eq2];
    ll s1 = spaces[eq1];
    ll s2 = spaces[eq2];
    ll ind1 = indents[eq1];
    ll ind2 = indents[eq2];
    // return -1 if no solution
    // return 1 if infinite solutions
    // return 0 if one solution
    spt = -1;
    spi = -1;
    if(ind1 == 0){
        if(s1 != 0 || t1 != 0)
            return -1;
    }
    if(ind2 == 0){
        if(s2 != 0 || t2 != 0)
            return -1;
    }

    if(t1 == 0 && t2 != 0){
        if(s1%ind1)
            return -1;
        spi = s1/ind1;
    }
    else if(t2 == 0 && t1 != 0){
        if(s2%ind2)
            return -1;
        spi = s2/ind2;
    }else if(t1 == 0 && t2 == 0){
        if(s2%ind2)
            return -1;
        if(s1%ind1)
            return -1;
        if(s1/ind1 != s2/ind2)
            return -1;
        return 1;
    }
    if(t1*ind2 == t2*ind1){
        if(ind1*s2 == ind2*s1)
            return 1;
        else
            return -1;
    }
    ll a1 = t1;
    ll a2 = t2;
    ll b1 = -ind1;
    ll b2 = -ind2;
    ll c1 = s1;
    ll c2 = s2;
    ll spt_num = b1*c2 - b2*c1;
    ll spt_den = a1*b2 - a2*b1;
    ll spi_num = c1*a2 - c2*a1;
    ll spi_den = spt_den;

    if(spt_num%spt_den || spi_num%spi_den)
        return -1;
    
    spt = spt_num/spt_den;
    spi = spi_num/spt_den;
    return 0;


    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    vector<string> arr(n);
    for(ll i =0 ;i<n;i++)
        cin>>arr[i];

    indents.resize(n);
    spaces.resize(n);
    tabs.resize(n);

    ll cur_indent = 0;
    for(ll i = 0;i<n;i++){
        ll tab_count = 0;
        ll space_count = 0;
        ll stack_change = 0;
        for(ll j = 0;j<arr[i].size();j++){
            if(arr[i][j] == 's')
                space_count++;
            else if(arr[i][j] == 't')
                tab_count++;
            else if(arr[i][j] == '{')
                stack_change = 1;
            else 
                stack_change = -1;
        }
        if(stack_change == 1){
            indents[i] = cur_indent;
            cur_indent += stack_change;
        }
        else{
            cur_indent += stack_change;
            indents[i] = cur_indent;
        }
        tabs[i] = tab_count;
        spaces[i] = space_count;
    }
    // cout<<"indents: ";
    // for(auto i: indents)
        // cout<<i<<" ";
    // cout<<endl;
    // cout<<"spaces: ";
    // for(auto i: spaces)
        // cout<<i<<" ";
    // cout<<endl;
    // cout<<"tabs: ";
    // for(auto i: tabs)
        // cout<<i<<" ";
    // cout<<endl;
    ll ans = 1;
    ll ok = 1;
    ll spaces_per_tab = -1;
    ll spaces_per_indent = -1;
    ll eq1=-1;
    ll spi = -1, spt = -1;
    for(ll i =0 ;i<n;i++){
        ll s = spaces[i];
        ll t = tabs[i];
        ll in = indents[i];
        if(!in && (s || t)){
            ok = 0;
            break;
        }
        else if(!in && !(s || t)){
            continue;
        }
        if(eq1 == -1){
            eq1 = i;
            continue;
        }
        ll ret = solve(eq1, i, spt, spi);
        if(ret == -1){
            ok = 0;
            break;
        }
        if(ret == 1)
            continue;
        if(ret == 0)
            break;
    }
    for(ll i = 0 ;i<n;i++){
        if(tabs[i]*spi + spaces[i] != indents[i]*spi)
            ok = 0;
    }
    if(!ok){
        cout<<"-1\n";
        return 0;
    }
    if(spt > 0)
        ans = spt;
    cout<<ans<<endl;

}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3480kb

input:

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3456kb

input:

4
{
ss{
ss}
}

output:

-1

result:

wrong answer 1st lines differ - expected: '1', found: '-1'